--- gnome-vfs-2.20.1/modules/sftp-method.c.BAD	2007-12-09 12:21:20.000000000 +0100
+++ gnome-vfs-2.20.1/modules/sftp-method.c	2007-12-09 12:23:03.000000000 +0100
@@ -678,9 +678,13 @@
 {
 	Buffer msg;
 	guint type, id, status;
+	GnomeVFSResult res;
 
 	buffer_init (&msg);
-	buffer_recv (&msg, fd);
+	if ((res = buffer_recv (&msg, fd)) != GNOME_VFS_OK) {
+		buffer_free (&msg);
+		return res;
+	}
 	type = buffer_read_gchar (&msg);
 	id = buffer_read_gint32 (&msg);
 
@@ -705,9 +709,13 @@
 	Buffer msg;
 	gchar type;
 	guint id, status;
+	GnomeVFSResult res;
 
 	buffer_init (&msg);
-	buffer_recv (&msg, fd);
+	if ((res = buffer_recv (&msg, fd)) != GNOME_VFS_OK) {
+		buffer_free (&msg);
+		return res;
+	}
 
 	type = buffer_read_gchar (&msg);
 	id = buffer_read_gint32 (&msg);
@@ -745,7 +753,10 @@
 	GnomeVFSResult res;
 
 	buffer_init (&msg);
-	buffer_recv (&msg, fd);
+	if ((res = buffer_recv (&msg, fd)) != GNOME_VFS_OK) {
+		buffer_free (&msg);
+		return res;
+	}
 
 	type = buffer_read_gchar (&msg);
 	id = buffer_read_gint32 (&msg);
@@ -2284,6 +2306,7 @@
 	guint curr_offset;
 	const guchar *buffer;
 	int queue_len;
+	GnomeVFSResult res;
 
 	struct WriteRequest 
 	{
@@ -2340,7 +2363,13 @@
 		}
 
 		buffer_clear (&msg);
-		buffer_recv (&msg, handle->connection->in_fd);
+		res = buffer_recv (&msg, handle->connection->in_fd);
+		if (res != GNOME_VFS_OK) {
+			buffer_free (&msg);
+			g_free (write_req);
+			sftp_connection_unlock (handle->connection);
+			return res;
+		}
 		type = buffer_read_gchar (&msg);
 		recv_id = buffer_read_gint32 (&msg);
 
@@ -2481,7 +2510,10 @@
 
 	buffer_clear (&msg);
 
-	buffer_recv (&msg, connection->in_fd);
+	if (buffer_recv (&msg, connection->in_fd) != GNOME_VFS_OK) {
+		buffer_free (&msg);
+		return NULL;
+	}
 
 	type = buffer_read_gchar (&msg);
 	recv_id = buffer_read_gint32 (&msg);
@@ -2715,6 +2747,7 @@
 
 	URI_TO_PATH (uri, path);
 	res = get_file_info_for_path (conn, path, file_info, options);
+	conn->status = res;
 	g_free (path);
 
 	sftp_connection_unref (conn);
@@ -2743,6 +2776,7 @@
 	res = get_file_info_for_path (handle->connection,
 				      handle->path,
 				      file_info, options);
+	handle->connection->status = res;
 	sftp_connection_unlock (handle->connection);
 	return res;
 }
@@ -2847,6 +2881,7 @@
 	gint status, count, i;
 	Buffer msg;
 	gchar type;
+	GnomeVFSResult res;
 
 	DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s: Enter", G_GNUC_FUNCTION));
 
@@ -2878,7 +2913,11 @@
 
 	buffer_clear (&msg);
 
-	buffer_recv (&msg, handle->connection->in_fd);
+	if ((res = buffer_recv (&msg, handle->connection->in_fd)) != GNOME_VFS_OK) {
+		buffer_free (&msg);
+		sftp_connection_unlock (handle->connection);
+		return res;
+	}
 
 	type = buffer_read_gchar (&msg);
 	recv_id = buffer_read_gint32 (&msg);
