Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.3k views
in Java FTP by (160 points)
Hi!

We have to connect to a ftp server over ISDN. The ISDN connection is created on demand. If the ISDN connection is closed, creating a FTP connection would take around 40 seconds. Because of that we set the timeout to 2 minutes. In the example I created a small program which used a timeout of 60 seconds which was set as command line argument. Therefore the code example is just an example that you see how we set the timeout.

FTPClient ftp = new FTPClient();
ftp.setTimeout(60 * 1000);


But when we try to connect

ftp.connect();


we are getting a SocketTimeoutException after 20 seconds. I set the log level to debug. This are the logs:

INFO 2013-01-10 09:22:23,326 host: 192.168.0.13
INFO 2013-01-10 09:22:23,342 timeout in milliseconds: 60000
INFO 2013-01-10 09:22:23,342 user: test
DEBUG 2013-01-10 09:22:23,373 Class: com.enterprisedt.net.ftp.FTPClient
Location: file:/C:/Users/IRM/FtpConnectionTester_10.01.2012/FtpConnectionTester/lib/edtftpj-2.3.0.jar
Version: 2.3.0
Build timestamp: 26-Aug-2011 13:52:07 EST
Java version: 1.6.0_20
CLASSPATH: .;FtpConnectionTester.jar;lib\commons-cli-1.2.jar;lib\commons-logging-1.1.jar;lib\log4j-1.2.13.jar;lib\edtftpj-2.3.0.jar
OS name: Windows Server 2008 R2
OS arch: amd64
OS version: 6.1

INFO 2013-01-10 09:22:23,373 starting connect
DEBUG 2013-01-10 09:22:23,373 Connecting to /192.168.0.13:21
ERROR 2013-01-10 09:22:44,420 java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.enterprisedt.util.proxy.PlainSocket.createPlainSocket(PlainSocket.java:122)
at com.enterprisedt.net.ftp.FTPControlSocket.<init>(FTPControlSocket.java:378)
at com.enterprisedt.net.ftp.FTPClient.connect(FTPClient.java:1003)
at at.irm.iopt.ftp.ConnectionTimeoutTest.run(ConnectionTimeoutTest.java:87)
at at.irm.iopt.ftp.ConnectionTimeoutTest.main(ConnectionTimeoutTest.java:104)


For sure, as a workaround I can create a loop around the connect statement and try to connect again, until 2 minutes are reached. But maybe you can solve it on your side, what I would like quit more.

Best regards

Markus

3 Answers

0 votes
by (161k points)
This timeout value should be passed into the socket.connect() method. Can you try with a plain socket connecting to the same IP and port?
0 votes
by (160 points)
It seems that Socket doesn't accespt timeouts > 20 seconds => see the log output:

INFO 2013-01-15 10:57:11,853 connecting to /192.168.0.13:21
INFO 2013-01-15 10:57:11,853 using timeout of 60 second(s)
INFO 2013-01-15 10:57:11,853 start connecting
ERROR 2013-01-15 10:57:32,869 java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at at.irm.iopt.ftp.PlainSocketConnection.run(PlainSocketConnection.java:39)
at at.irm.iopt.ftp.PlainSocketConnection.main(PlainSocketConnection.java:52)

For me it would be interesting if you plan to solve it on your side. If not I would just implement my own timeout and loop while it is not reached.
0 votes
by (161k points)
If the Java socket itself doesn't wait any longer than 20 sec irrespective of the timeout supplied, there's not much we can do about it.

You're not the first person to note this:

http://stackoverflow.com/questions/1339 ... -platforms

Categories

...