--- gnome-vfs2-2.14.2/modules/sftp-method.c	2006-03-20 18:47:35.000000000 +0100
+++ gnome-vfs2-2.14.2.patch/modules/sftp-method.c	2006-07-19 22:03:54.985693500 +0200
@@ -164,6 +164,10 @@
 						GIOCondition cond,
 						GnomeVFSResult *status);
 
+static GnomeVFSResult do_close (GnomeVFSMethod       *method,
+				GnomeVFSMethodHandle *method_handle,
+				GnomeVFSContext      *context);
+
 typedef struct
 {
 	char  *base;
@@ -1808,8 +1812,35 @@
 
 		sftp_connection_unlock (conn);
 
-		DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s: Exit", __FUNCTION__));
-		return GNOME_VFS_OK;
+		/* Before returning, check if given handle is really a file or a directory */
+		{
+			GnomeVFSFileInfo *file_info;
+			GnomeVFSResult res;
+
+			file_info = gnome_vfs_file_info_new();
+			
+			res = do_get_file_info_from_handle(method, *method_handle, file_info, GNOME_VFS_FILE_INFO_DEFAULT, context);
+			
+			if (res == GNOME_VFS_OK &&
+			    (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE != 0) &&
+			    file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
+
+				/* As we are going to return an error : close the handle and set method_handle to null */
+				do_close(method, *method_handle, context);
+				*method_handle = NULL;
+				gnome_vfs_file_info_unref(file_info);
+
+				DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s: Exit", __FUNCTION__));
+				return GNOME_VFS_ERROR_IS_DIRECTORY;
+			}
+
+			gnome_vfs_file_info_unref (file_info);
+			DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s: Exit", __FUNCTION__));
+			/* the first operation (SSH2_FXP_OPEN) returned OK and we are unable to determine if 
+			   requested uri is a file or a directory. We treat it as a file and return GNOME_VFS_OK */
+			return GNOME_VFS_OK;
+		}
+
 	} else {
 		*method_handle = NULL;
 
