Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 53485 invoked from network); 23 Jun 2003 19:01:51 -0000 Received: from unknown (HELO sawmailsf1.sawyermedia.local) (206.14.190.67) by daedalus.apache.org with SMTP; 23 Jun 2003 19:01:51 -0000 X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: [VFS][patch] idle FTP connections throw exceptions Date: Mon, 23 Jun 2003 12:01:56 -0700 Message-ID: <378277A8F8AD4049AD8BC80D1F2B953930ACE6@sawmailsf1.sawyermedia.local> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [VFS][patch] idle FTP connections throw exceptions Thread-Index: AcM5ueqrK1GemSKCSAO7vFu3NuaPVw== From: "Jeff Barrett" To: X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 = :=20 server =3D _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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/v= fs/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 =3D rootName.getUserName(); + username =3D URLDecoder.decode( rootName.getUserName() ); } if ( rootName.getPassword() =3D=3D null ) { @@ -105,7 +108,7 @@ } else { - password =3D rootName.getPassword(); + password =3D 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 =3D createConnection(); + } + final FTPClient client =3D idleClient; idleClient =3D 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. =20