Why doesn't FTPClient.setDefaultTimeout work?
I am trying to make a ftp connection in Java with FTPClient.
I wanted to look what happens when i separate the line开发者_高级运维 between Server and Client. My application freezed about 30seconds and then it thows aConnectionException
(Connection timed out). Thats why I searched for a timeout method for the FTPCliend and I found setDefaultTimeout()
so I put the method before the connection attemp but it still freezed 30 sec...
FTPClient ftp = new FTPClient();
ftp.setDefaultTimeout(5000);
ftp.connect(ip);
When i put "1.1.1.1" as ip
the application throws fastly a ConnectionException
(Connection refused) but when i put the right ipAdress its just freezing(30sec) and threwing the ConnectionException
instead of the wished TimeoutException (after 5sec)
What am I doing wrong?
ps: excuse my horrible english knowledge ;)
I'm not sure which FTPClient
you're using because there are a couple out there. However, they usually have two different timeout options : one for data and one for actual connection. I suggest you search for a method called setConnectTimeout()
or similar.
精彩评论