Index: modules/ftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/ftp-method.c,v
retrieving revision 1.115
diff -u -r1.115 ftp-method.c
--- modules/ftp-method.c	13 Apr 2005 19:58:55 -0000	1.115
+++ modules/ftp-method.c	1 May 2005 17:24:41 -0000
@@ -123,6 +123,9 @@
 	gchar *server_type; /* the response from TYPE */
 	GnomeVFSResult fivefifty; /* the result to return for an FTP 550 */
 
+	gboolean supports_hidden_files;
+	gboolean supports_hidden_files_init;
+
 #ifdef HAVE_GSSAPI
 	gboolean use_gssapi;
 	gss_ctx_id_t gcontext;
@@ -245,6 +248,8 @@
 	case 451:
 	case 551:
 	  return GNOME_VFS_ERROR_NOT_FOUND;
+	case 504:
+	  return GNOME_VFS_ERROR_BAD_PARAMETERS;
 	case 550:
 	  return conn->fivefifty;
 	case 452:
@@ -1251,6 +1256,7 @@
 	conn->response_buffer = g_string_new ("");
 	conn->response_code = -1;
 	conn->fivefifty = GNOME_VFS_ERROR_NOT_FOUND;
+	conn->supports_hidden_files_init = FALSE;
 	
 	user = NULL;
 	pass = NULL;
@@ -2343,14 +2349,50 @@
 	result = do_path_command (conn, "CWD", uri, cancellation);
 	if (result != GNOME_VFS_OK) {
 		ftp_connection_release (conn, TRUE);
+		g_string_free (dirlist, TRUE);
 		return result;
 	}
 
+	/* check whether the server supports showing hidden files,
+	 * if we haven't already. If we pass the check, we can read
+	 * the directory straight ahead. */
+	if (!conn->supports_hidden_files_init) {
+		result = do_transfer_command (conn,
+					      strstr (conn->server_type, "MACOS") ? "LIST -a" : "LIST -aL",
+					      context);
+
+		conn->supports_hidden_files_init = TRUE;
+
+		switch (result) {
+			/* supports hidden files.
+			 * ready to read directory */
+			case GNOME_VFS_OK:
+				conn->supports_hidden_files = TRUE;
+				goto read;
+				break;
+
+			/* does not support hidden files.
+			 * retry without -a flag (see below) */
+			case GNOME_VFS_ERROR_BAD_PARAMETERS:
+				conn->supports_hidden_files = FALSE;
+				break;
+
+			default:
+				ftp_connection_release (conn, TRUE);
+				g_string_free (dirlist, TRUE);
+				return result;
+		}
+	}
+
 	if(strstr(conn->server_type,"MACOS")) {
 		/* don't ask for symlinks from MacOS servers */
-		result = do_transfer_command (conn, "LIST", context);
+		result = do_transfer_command (conn,
+					      conn->supports_hidden_files ? "LIST -a" : "LIST",
+					      context);
 	} else {
-		result = do_transfer_command (conn, "LIST -L", context);
+		result = do_transfer_command (conn,
+					      conn->supports_hidden_files ? "LIST -aL" : "LIST -L",
+					      context);
 	}
 
 	if (result != GNOME_VFS_OK) {
@@ -2359,6 +2401,7 @@
 		return result;
 	}
 
+read:
 	while (result == GNOME_VFS_OK) {
 		result = gnome_vfs_socket_buffer_read (conn->data_socketbuf, buffer, 
 						       num_bytes, &bytes_read,
