--- t:libssh2-1.4.3/src/sftp.c	2012-11-13 00:23:01 +0000
+++ code:ports/libssh2/libssh2-1.4.3/src/sftp.c	2013-08-09 14:20:57 +0000
@@ -516,6 +516,16 @@
         return LIBSSH2_ERROR_NONE;
     }
 
+    if (packet_type == SSH_FXP_EXTENDED_REPLY) {
+        if (sftp_packet_ask(sftp, SSH_FXP_STATUS, request_id, data, data_len) == 0) {
+            /* There was a STATUS returned with our request_id on it.. */
+            /* We got it and now lets free it and return error. */
+            libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Got STATUS instead of EXTENDED_REPLY, OK");
+            LIBSSH2_FREE(session, *data);      
+            return LIBSSH2_ERROR_SFTP_PROTOCOL;
+        }    
+    } 
+
     while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
         rc = sftp_packet_read(sftp);
         if (rc < 0)
@@ -528,6 +538,16 @@
                            (int) packet_type);
             return LIBSSH2_ERROR_NONE;
         }
+        
+        if (packet_type == SSH_FXP_EXTENDED_REPLY) {
+            if (sftp_packet_ask(sftp, SSH_FXP_STATUS, request_id, data, data_len) == 0) {
+                /* There was a STATUS returned with our request_id on it.. */
+                /* We got it and now lets free it and return error. */
+               _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Got STATUS instead of EXTENDED_REPLY, OK");
+                LIBSSH2_FREE(session, *data);      
+                return LIBSSH2_ERROR_SFTP_PROTOCOL;
+            }    
+        } 
     }
 
     /* Only reached if the socket died */
