title: Unable to connect to FTP in Android
body: <p>I've checked the other answers and they didn't help me with this error. Maybe I'm doing something else wrong.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    void uploadPic() throws FileNotFoundException
  {
      FileInputStream fis = new FileInputStream(path);
      FTPClient con = new FTPClient();
      int bytesAvailable;
      try
      {
          con.connect("ftp://ftp.drivehq.com/");
          Toast.makeText(this, "Connected to FTP", Toast.LENGTH_SHORT).show();
          if (con.login("x", "x"))
          {
              Toast.makeText(this, "Logged in", Toast.LENGTH_SHORT).show();
              con.enterLocalPassiveMode(); // Active mode doesn't really work on Android
              bytesAvailable = fis.available();
              byte[] barray = new byte[bytesAvailable];
              fis.read(barray);
              ByteArrayInputStream in = new ByteArrayInputStream(barray);
              boolean result = con.storeFile("/CameraUpload.jpg", in);
              in.close();
              if (result) Log.v("Upload Result", "Succeeded");
          }
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I've added INTERNET permission to my project.
  The logcat shows these errors:</p>
  
  <pre><code>android.os.NetworkOnMainThreadException
  W/System.err(17531):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
  W/System.err(17531):    at java.net.InetAddress.lookupHostByName(InetAddress.java:391
  </code></pre>
  
  <p>I'm connected to the internet via Wifi.</p>