I'm trying to learn how to connect my app to a certain FTP server. For this purpose , Im using Apache Commons net which is quite good. So far I managed to connect my app to the FTP server while Im connected to the WiFi. While Im connected to the Wi-Fi, Its connecting and logging in smoothly, yet, when I try to connect my FTP server with my celluar network It gives me connection timeout error. First I thought this because of my cellular network speed. Therefore I increased the timeout for giving my cellular network much more time to connect but It didn't work. I mean It's basicly not working. Here is the code Im using. Its in a class which is extended by AsyncTask.
@Override
protected String doInBackground(String[] params) {
String temp = "Files : \n";
FTPClient client = new FTPClient();
client.setConnectTimeout(360 * 1000);
client.setDefaultTimeout(360 * 1000);
try {
Log.d("FtpDebug", "Connecting ...");
client.connect(myftpservername);
client.enterLocalPassiveMode();
Log.d("FtpDebug","Connected!");
}catch (Exception e){
Log.d("FtpError", e.toString());
}
I said its not working because it gives me this error
D/FtpError: java.net.SocketTimeoutException: failed to connect to xxx.xx.xxxx.xx.xx/xxx.xxx.xx.x (port 21) after 360000ms: isConnected failed: ETIMEDOUT (Connection timed out)
In this error it says It failed to connect after trying 360.000ms=6 minutes. But actually , Im getting this error in 1 minute or less than 1 minute.So Its not even waiting for 6 minutes.
It is clear that Im doing something wrong. I would be really happy if someone point that out. Thanks.