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 a ConnectionException(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
FTPClientyou’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 calledsetConnectTimeout()or similar.