Index: src/scp.c
===================================================================
RCS file: /cvsroot/libssh2/libssh2/src/scp.c,v
retrieving revision 1.14
diff -u -r1.14 scp.c
--- src/scp.c	12 Jun 2007 18:27:50 -0000	1.14
+++ src/scp.c	4 Jul 2007 11:57:45 -0000
@@ -583,9 +583,27 @@
         libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response", 0);
         return NULL;
     }
-    else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
-        libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
-        goto scp_send_error;
+    else {
+        if (rc <= 0) {
+            libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
+            goto scp_send_error;
+        }
+        if (session->scpSend_response[0] != 0) {
+            /* Handle error sent by remote scp */
+            char err_msg[1024];
+            char *p_err_msg = err_msg;
+            /* Read the remote error message */
+            do {
+                rc = libssh2_channel_read_ex(session->scpSend_channel, 0, 
+                    (char *)session->scpSend_response, 1);
+                if (rc <= 0)
+                    break;
+                *p_err_msg++ = session->scpSend_response[0];
+            } while ((p_err_msg - err_msg) < sizeof(err_msg));
+            *p_err_msg = '\0';
+            libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, err_msg, 0);
+            goto scp_send_error;
+        }
     }
     
     session->scpSend_state = libssh2_NB_state_idle;
