Index: lib/ssh.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/ssh.c,v
retrieving revision 1.26
diff -u -r1.26 ssh.c
--- lib/ssh.c	2 Apr 2007 21:24:05 -0000	1.26
+++ lib/ssh.c	3 Apr 2007 01:39:37 -0000
@@ -158,6 +158,7 @@
 #endif
 
 /* Local functions: */
+static const char *sftp_libssh2_strerror(unsigned long err);
 static CURLcode sftp_sendquote(struct connectdata *conn,
                                struct curl_slist *quote);
 
@@ -210,6 +211,9 @@
   /* TODO: map some of the libssh2 errors to the more appropriate CURLcode
      error code, and possibly add a few new SSH-related one. We must however
      not return or even depend on libssh2 errors in the public libcurl API */
+  
+  if (errorcode == LIBSSH2_FX_NO_SUCH_FILE)
+     return CURLE_REMOTE_FILE_NOT_FOUND;
 
   return CURLE_SSH;
 }
@@ -304,7 +308,7 @@
   ssh->ssh_session = libssh2_session_init_ex(libssh2_malloc, libssh2_free,
                                             libssh2_realloc, ssh);
   if (ssh->ssh_session == NULL) {
-    failf(data, "Failure initialising ssh session\n");
+    failf(data, "Failure initialising ssh session");
     Curl_safefree(ssh->path);
     Curl_safefree(working_path);
     return CURLE_FAILED_INIT;
@@ -315,7 +319,7 @@
 #endif /* CURL_LIBSSH2_DEBUG */
 
   if (libssh2_session_startup(ssh->ssh_session, sock)) {
-    failf(data, "Failure establishing ssh session\n");
+    failf(data, "Failure establishing ssh session");
     libssh2_session_free(ssh->ssh_session);
     ssh->ssh_session = NULL;
     Curl_safefree(ssh->path);
@@ -434,12 +438,12 @@
   authlist = NULL;
 
   if (!authed) {
-    failf(data, "Authentication failure\n");
+    failf(data, "Authentication failure");
     libssh2_session_free(ssh->ssh_session);
     ssh->ssh_session = NULL;
     Curl_safefree(ssh->path);
     Curl_safefree(working_path);
-    return CURLE_FAILED_INIT;
+    return CURLE_LOGIN_DENIED;
   }
 
   /*
@@ -716,8 +720,11 @@
                         LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT,
                         LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
                         LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
-    if (!sftp->sftp_handle)
-      return CURLE_FAILED_INIT;
+    if (!sftp->sftp_handle) {
+      failf(conn->data, "Could not open remote file for writing: %s",
+            sftp_libssh2_strerror(libssh2_sftp_last_error(sftp->sftp_session)));
+      return libssh2_error_to_CURLE(conn);
+    }
 
     /* upload data */
     res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
@@ -738,8 +745,11 @@
 
       sftp->sftp_handle =
         libssh2_sftp_opendir(sftp->sftp_session, sftp->path);
-      if (!sftp->sftp_handle)
-        return CURLE_SSH;
+      if (!sftp->sftp_handle) {
+        failf(conn->data, "Could not open directory for reading: %s",
+            sftp_libssh2_strerror(libssh2_sftp_last_error(sftp->sftp_session)));
+        return libssh2_error_to_CURLE(conn);
+      }
 
       while ((len = libssh2_sftp_readdir(sftp->sftp_handle, filename,
                                          PATH_MAX, &attrs)) > 0) {
@@ -876,8 +886,11 @@
         libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
                           LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
                           LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
-      if (!sftp->sftp_handle)
-        return CURLE_SSH;
+      if (!sftp->sftp_handle) {
+        failf(conn->data, "Could not open remote file for reading: %s",
+            sftp_libssh2_strerror(libssh2_sftp_last_error(sftp->sftp_session)));
+        return libssh2_error_to_CURLE(conn);
+      }
 
       if (libssh2_sftp_stat(sftp->sftp_session, sftp->path, &attrs)) {
         /*

