--- gnome-vfs-2.20.1/modules/sftp-method.c.BAD	2007-12-09 15:10:30.000000000 +0100
+++ gnome-vfs-2.20.1/modules/sftp-method.c	2007-12-09 15:11:58.000000000 +0100
@@ -1550,6 +1550,10 @@
 	return res;
 }
 
+static gboolean sftp_connection_close (SftpConnection *);
+static void sftp_connection_lock (SftpConnection *);
+static void sftp_connection_unlock (SftpConnection *);
+
 static GnomeVFSResult
 sftp_get_connection (SftpConnection **connection, const GnomeVFSURI *uri) 
 {
@@ -1586,6 +1588,26 @@
 
 	*connection = g_hash_table_lookup (sftp_connection_table, hash_name);
 
+	/* 
+	 * if current connection is stalled with status GNOME_VFS_ERROR_IO
+	 * it may mean that the sftp subprocess timed out or just
+	 * aborted abnormally. In this case, we try to transparently
+	 * reconnect.
+	 */
+	if (*connection && (*connection)->status != GNOME_VFS_OK) {
+		DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
+			      "%s: IO Error occured, reconnecting.", G_GNUC_FUNCTION));
+		sftp_connection_lock ((*connection));
+		if ((*connection)->close_timeout_id > 0) {
+			g_source_remove ((*connection)->close_timeout_id);
+			(*connection)->close_timeout_id = 0;
+		}
+		g_hash_table_remove (sftp_connection_table, (*connection)->hash_name);
+		sftp_connection_unlock ((*connection));
+		sftp_connection_close ((*connection));
+		*connection = NULL;
+	}
+
 	if (*connection == NULL) {
 		DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
 			      "%s: Connection not found. Opening new one.", G_GNUC_FUNCTION));
