androidftp4g

Android FTP with 4G


I am trying to connect to an FTP server in an Android application and I believe that I fall in an infinite loop, but can't understand why. The library I am using is Apache Comomns net.

I have the internet permission in manifest :

<uses-permission android:name="android.permission.INTERNET"/>

I am also connecting to the FTP in an AsyncTask.

Here is a sample code which was supposed to work :

    // I have other values when I test it of course
    FTPClient ftpClient = new FTPClient();
    ftpClient.connect("111.111.111.111"); // It stops working here when in 4G
    ftpClient.login("user", "mdp");
    ftpClient.changeWorkingDirectory("directory");
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    ftpClient.enterLocalPassiveMode();
    ftpClient.logout();
    ftpClient.disconnect();

It works on Wifi (and my real application works too in wifi) but when I use my 4G (or 3G) it seems to loop at the line where I try to connect() forever.

I have tryed to understand what there is behind this but it's not clear for me.

How can I connect to my FTP using 4G?

Any help would be appreciated.


Solution

  • It sounds like your network operator may have the FTP port blocked.

    To test this you can try to ftp to the same site on a browser in your mobile device - if it works then it point to an issue in your app.

    If it does not work then try with a known working FTP site - Tele2 host a test site for example (there are lot of other open FTP sites if you do a quick search):

    If you can't access this from your mobile device over 4G then it looks very likely that your operator has FTP, and you should contact them to find out why and what you can do to remove the block.