commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r940808 - /commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java
Date Tue, 04 May 2010 11:20:58 GMT
Author: imario
Date: Tue May  4 11:20:57 2010
New Revision: 940808

URL: http://svn.apache.org/viewvc?rev=940808&view=rev
Log:
VFS-307: speedup directory listing if ftp server supports list with pathnames with spaces

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java?rev=940808&r1=940807&r2=940808&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java
Tue May  4 11:20:57 2010
@@ -16,18 +16,19 @@
  */
 package org.apache.commons.vfs.provider.ftp;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemOptions;
 import org.apache.commons.vfs.UserAuthenticationData;
 import org.apache.commons.vfs.provider.GenericFileName;
 import org.apache.commons.vfs.util.UserAuthenticatorUtils;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 /**
  * A wrapper to the FTPClient to allow automatic reconnect on connection loss.<br />
  * I decided to not to use eg. noop() to determine the state of the connection to avoid
@@ -128,6 +129,18 @@ class FTPClientWrapper implements FtpCli
 
     private FTPFile[] listFilesInDirectory(String relPath) throws IOException
     {
+		FTPFile[] files;
+
+		// VFS-307: no check if we can simply list the files, this might fail if there are spaces
in the path
+		files = getFtpClient().listFiles(relPath);
+		if (FTPReply.isPositiveCompletion(getFtpClient().getReplyCode()))
+		{
+			return files;
+		}
+
+		// VFS-307: now try the hard way by cd'ing into the directory, list and cd back
+		// if VFS is required to fallback here the user might experience a real bad FTP performance
+		// as then every list requires 4 ftp commands.
         String workingDirectory = null;
         if (relPath != null)
         {
@@ -138,7 +151,7 @@ class FTPClientWrapper implements FtpCli
             }
         }
 
-        FTPFile[] files = getFtpClient().listFiles();
+        files = getFtpClient().listFiles();
 
         if (relPath != null && !getFtpClient().changeWorkingDirectory(workingDirectory))
         {



Mime
View raw message