title: Connection refused using FTP local passive mode in Android
body: <p>I am currently developing an Android application that has to connect herself to a local FTP server (I am using Filezilla server).
  I've downloaded the org.commons.apache.net ftp librabry.</p>
  
  <p>Here is my code relative to my android project :</p>
  
  <pre><code>    FTPClient mFTPClient = new FTPClient();
  
      try {
          mFTPClient = new FTPClient();
          mFTPClient.connect("10.0.2.2", 21);
  
          if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
              mFTPClient.login("lucas", "elie");
              mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
              mFTPClient.enterLocalPassiveMode();
          }
  
      } catch (SocketException e) {
          Log.e("TEST", "SocketException: " + e.getStackTrace().toString() + " " + e.getMessage());
      } catch (UnknownHostException e) {
          Log.e("TEST", "UnknownHostException: " + e.getStackTrace().toString() + " " + e.getMessage());
      } catch (IOException e) {
          Log.e("TEST", "IOException: " + e.getStackTrace().toString() + " " + e.getMessage());
      }
  
      //
  
      FileOutputStream desFileStream;
      try {
          desFileStream = new FileOutputStream("/mnt/sdcard/sample_0.jpg");
          mFTPClient.retrieveFile("/sample_0.jpg", desFileStream);
          desFileStream.close();
      } catch (FileNotFoundException e) {
          Log.e("TEST", "FileNotFoundException: " + e.getStackTrace().toString() + " " + e.getMessage());
      } catch (IOException e) {
          Log.e("TEST", "IOException: " + e.getStackTrace().toString() + " " + e.getMessage());
      }
  </code></pre>
  
  <p>The connection is working (mFTPClient.connect("10.0.2.2", 21);), as I can see it on my local server interface, but when i'm trying to download my file (mFTPClient.retrieveFile("/sample_0.jpg", desFileStream);), i'm getting an IOException in the Logcat : </p>
  
  <p>04-07 11:25:26.300: E/TEST(671): IOException: [Ljava.lang.StackTraceElement;@412ca688 failed to connect to /127.0.0.1 (port 2832): connect failed: ECONNREFUSED (Connection refused)</p>
  
  <p>I precise that I added these two lines in the Android Manifest XML file :</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&gt;&lt;/uses-permission&gt;
  </code></pre>
  
  <p>Using EXACTLY the same code, but in a classic Java project instead of an Android project, all works perfectly fine (replacing 10.0.2.2 by 127.0.0.1 and "/mnt/sdcard" by "C:\") !</p>
  
  <p>Could anyone help me please?</p>
  
  <p>EDIT : I found my mistake. If that can help someone, i simply had to replace 10.0.2.2 with my local IP adress (in my case 192.168.0.5)</p>