You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Barrie Selack <bs...@digipixart.com> on 2005/11/01 18:17:37 UTC

FTPClient occasionally opens port to self instead of server

I've been having strange timeouts with commons.net and the FTPClient. I
finally created my own CustomSocketFactory to set timeouts and see what
addresses/pots were in use. After many successful connections using the
client (for PASV, getting file lists) after some period of time, it
decides instead of opening a connection to the server, to open a
connection to itself. There is no specific time period of series of events.

I have the ftp server set to respond on ports 60000-61000

So in the log (only applicable portion) the lines for opening a socket
look like...


2005-11-01 11:55:44,165 DEBUG createSocket with host: 207.www.xx.yy,
port: 60724 with timeout of 300000
... lots of other debugging ...
2005-11-01 11:55:44,547 DEBUG createSocket with host: 207.www.xx.yy,
port: 60436 with timeout of 300000
... lots of other debugging ...
2005-11-01 11:55:44,949 DEBUG createSocket with host: 207.www.xx.yy,
port: 60127 with timeout of 300000
... lots of other debugging ...
2005-11-01 11:55:45,376 DEBUG createSocket with host: 207.www.xx.yy,
port: 60377 with timeout of 300000
... lots of other debugging ...
2005-11-01 11:55:45,953 DEBUG createSocket with host: 207.www.xx.yy,
port: 60985 with timeout of 300000
... lots of other debugging ...
2005-11-01 11:55:46,362 DEBUG createSocket with host: 207.www.xx.yy,
port: 60027 with timeout of 300000
... lots of other debugging ...
2005-11-01 11:55:46,751 DEBUG createSocket with host: 24.www.xxx.yy,
port: 51897 with timeout of 300000

Hey! that last address is MY local address, the one the client is running on!

So the connection times out, since there is nothing to connect to there,
I mean here.. well you know what I mean.

Has anyone seen such behavior.. does FTPClient just get lost?

Any help would be greatly appreciated.

Regards,

Barrie Selack




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: FTPClient occasionally opens port to self instead of server

Posted by Barrie Selack <bs...@digipixart.com>.
In the ftp log (pureFTPd) it never shows a PASV command for
24.www.xxx.yy, on for 10.2.1.10 (the local address behind a firewall). 

Could it be a firewall problem (SonicWall) getting the IP wrong. I hadn't
thought too much about that, but if it's the one rewriting the 10.2.1.10
address to the public IP, then it may be the one with the problem. Any
thoughts or experiences with that? The firewall is set up in one-to-one
NAT so 10.2.1.10 -> 207.www.xxx.yy

Barrie

>
>In message <20...@mail.digipixart.com>, "Barrie Selack"
writes:
>>PASV
>>227 Entering Passive Mode (24.www.xxx.yy,253,112)
>
>Okay, so that would mean it's not a bug in FTPClient.  The FTP server
>is sending back 24.www.xxx.yy as the IP address for the data connection
>instead of the 207.www.xx.yy it should be sending.  I couldn't see any
>way in the code for FTPClient to cause a local IP to be used, so that's
>consistent.  Unfortunately, it means your FTP server is at fault (or
>some library it depends on, maybe getsockname is buggy).
>
>>happens much more. Just FYI, I switched the code to use edtFTPj and
>>tested several times with no problems.
>
>If edtFTPj is working, then it won't work with FTP servers that have
>have multiple interfaces/IP addresses because it must not be parsing the
>PASV reply.
>
>I'm not sure how to proceed.  I'm hesitant to special-case a workaround
>for a buggy FTP server.  Any suggestions?
>
>daniel
>
>-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
>    s a v a r e s e      # In distant lands, I hear the call of my home.
>   software research     # Yet my work is not done.  My journey's just begun.
>http://www.savarese.com/ #  -- http://www.sleepandthetraveller.com/
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: FTPClient occasionally opens port to self instead of server

Posted by Barrie Selack <bs...@digipixart.com>.
Daniel,

Here's the logs snippets...

(syslog)

226-ASCII
226-Options: -l 
226 1 matches total
PASV
227 Entering Passive Mode (24.www.xxx.yy,253,112)
java.net.ConnectException: Operation timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
        at java.net.Socket.connect(Socket.java:452)
        at java.net.Socket.connect(Socket.java:402)
        at java.net.Socket.<init>(Socket.java:309)
        at java.net.Socket.<init>(Socket.java:124)
        at com.digipixart.application
.autodownload.CustomSocketFactory.createSocket(CustomSocketFactory.java:78)
        at org.apache.commons.net.ftp
.FTPClient._openDataConnection_(FTPClient.java:513)
        at org.apache.commons.net.ftp
.FTPClient.initiateListParsing(FTPClient.java:2390)
        at org.apache.commons.net.ftp
.FTPClient.initiateListParsing(FTPClient.java:2364)
        at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2141)
        at com.digipixart.application
.autodownload.ApacheDownloadFiles.downloadFiles(ApacheDownloadFiles.java:390)
        at com.digipixart.application
.autodownload.ApacheDownloadFiles.run(ApacheDownloadFiles.java:126)
        at java.lang.Thread.run(Thread.java:552)
java.lang.NullPointerException
        at com.digipixart.application
.autodownload.CustomSocketFactory.createSocket(CustomSocketFactory.java:91)
        at org.apache.commons.net.ftp
.FTPClient._openDataConnection_(FTPClient.java:513)
        at org.apache.commons.net.ftp
.FTPClient.initiateListParsing(FTPClient.java:2390)
        at org.apache.commons.net.ftp
.FTPClient.initiateListParsing(FTPClient.java:2364)
        at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2141)
        at com.digipixart.application
.autodownload.ApacheDownloadFiles.downloadFiles(ApacheDownloadFiles.java:390)
        at com.digipixart.application
.autodownload.ApacheDownloadFiles.run(ApacheDownloadFiles.java:126)
        at java.lang.Thread.run(Thread.java:552)


and from my application log...

2005-11-03 08:34:37,468 DEBUG createSocket with host: 24.www.xxx.yy,
port: 64880 with timeout of 300000
... blah blah blah ...
2005-11-03 08:42:33,157 DEBUG *** PassiveHost: 24.www.xxx.yy


I also get quite a few "Timeouts" with no apparent reason (where the IP
is correct, and the sever connects but nothing happens), but the wrong IP
happens much more. Just FYI, I switched the code to use edtFTPj and
tested several times with no problems.

also, it happened even before I created the CustomSocketFactory, which I
did just to get more debugging information (and set the timeouts).

I'm on Mac OS X 10.3.9 with Java 1.4.2, but also had the same type of
problems on Linux with Java 1.5.0

Regards,

Barrie


>
>In message <20...@mail.digipixart.com>, "Barrie Selack"
writes:
>>2005-11-01 11:55:46,362 DEBUG createSocket with host: 207.www.xx.yy,
>>port: 60027 with timeout of 300000
>>... lots of other debugging ...
>>2005-11-01 11:55:46,751 DEBUG createSocket with host: 24.www.xxx.yy,
>>port: 51897 with timeout of 300000
>>
>>Hey! that last address is MY local address, the one the client is
running on!
>...
>>Has anyone seen such behavior.. does FTPClient just get lost?
>>
>>Any help would be greatly appreciated.
>
>Can you print the value of FTPClient.getPassiveHost() immediately
>after that happens?  Also, can you log the FTP conversation with 
>PrintCommandListener from src/java/examples/ so we can see how the FTP
>server is responding to the PASV command?
>
>For FTPClient hackers:
>The only way I see this happening is if __passiveHost is null
>when the socket is created.  __passiveHost is set to null by
>enterLocalPassiveMode() and is given a value by _openDataConnection_()
>by calling __parsePassiveReply() after issuing a successful pasv().
>So if __parsePassiveReply() doesn't set __passiveHost, it
>will remain null when SocketFactory.createSocket() is called,
>causing Socket() to be called with a null host, which will
>cause the local host IP to be used.  However, I don't see how
>__parsePassiveReply() can leave __passiveHost null without
>throwing an exception.  Therefore, the need for the extra
>information.
>
>daniel
>
>-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
>    s a v a r e s e      # In distant lands, I hear the call of my home.
>   software research     # Yet my work is not done.  My journey's just begun.
>http://www.savarese.com/ #  -- http://www.sleepandthetraveller.com/
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org