I've noticed that leaving an FTP provider idle for a while, and thereby the FTP
connection idle, causes exceptions to be thrown on subsequent client-server
communication. I didn't have too much time to investigate the problem. Unfortunately
FTPClient.isConnection() will still return true when the connection is in this "stale"
state. One clear symptom was the following line in the commons-net
FTPClient.__openDataConnection :
server = _socketFactory_.createServerSocket(0, 1, getLocalAddress());
that call to getLocalAddress returns 255.255.255.255 when the state of the connection
is bad.
Anyway, I have a cheesy workaround. The diff below also includes some
URLEncode/decode stuff from another patch I submitted. You may include or remove this
as you see fit.
Index: src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java,v
retrieving revision 1.21
diff -u -r1.21 FtpFileSystem.java
--- src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java 14 Apr 2003
01:09:25 -0000 1.21
+++ src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java 23 Jun 2003
18:52:34 -0000
@@ -56,6 +56,9 @@
package org.apache.commons.vfs.provider.ftp;
import java.io.IOException;
+import java.net.BindException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import java.util.Collection;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
@@ -97,7 +100,7 @@
}
else
{
- username = rootName.getUserName();
+ username = URLDecoder.decode( rootName.getUserName() );
}
if ( rootName.getPassword() == null )
{
@@ -105,7 +108,7 @@
}
else
{
- password = rootName.getPassword();
+ password = URLDecoder.decode( rootName.getPassword() );
}
}
@@ -166,6 +169,23 @@
}
else
{
+
+ /*
+ * It seems there are cases that leaving an ftp
+ * connection idle for a while will cause errors.
+ * client.isConnected() doesnt help here. these errors
+ * are manifested as IOExceptions thrown when sending
+ * commands to the FTP server. The below will
+ * make sure the connection still works. If it doesn't
+ * it will re-establish it.
+ */
+ try {
+ idleClient.getStatus();
+ } catch (IOException e) {
+ closeConnection( idleClient );
+ idleClient = createConnection();
+ }
+
final FTPClient client = idleClient;
idleClient = null;
return client;
The information in this email and subsequent attachments may contain confidential
information that is intended solely for the attention and use of the named
addressee(s). This message or any part thereof must not be disclosed, copied,
distributed, or retained by any person without the authorization from the addressee.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]