3

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.

leb1755
  • 1,386
  • 2
  • 14
  • 29

1 Answers1

3

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.

Mick
  • 24,231
  • 1
  • 54
  • 120
  • Thank you very much ! I didn't expect an issue like that but I just tryed it with an other application to connect to my FTP server (I did it also with speedtest.tele2.net) with Wifi and with 4G : it only works in wifi too. Do you know if it's a common practice? (I live in France) – leb1755 Jun 01 '15 at 08:44
  • @Sébastien - It certainly is common practice for Mobile operators to block things, but I'm not sure how common blocking FTP is. Probably not uncommon if they are trying to reduce network load. Mobile networks are complicated and you may find, even with the same operator, something is blocked on one device but not another, or not on a 'dongle'. This is because they have mechanisms to define 'profiles' and apply traffic steering and policing rules based on this (you may notice different devices use different 'APN's'). – Mick Jun 02 '15 at 10:29
  • I guess I will have to stay on Wifi then. Maybe I could work with a webservice or something that can give me access to my files on my FTP but without using it directly on the mobile network... – leb1755 Jun 02 '15 at 12:08
  • May be it is the firewall on your server preventing ftp access – Amt87 Jan 24 '17 at 14:01