how to connect to ftp server from android
<p>I  have gone through many discussion about uploading file from ftp server.I think there are 2 ways to connect and upload:</p>

<p>1: I must use apache library and use its classes like ftpclient. </p>

<p>2: With URLConnection like this code: </p>

<pre class="lang-java prettyprint-override"><code>    public void getFile(URL u) throws IOException { 
        // url de type "http://www.monsite.com/monrep/mavideo.wmv" 
        String FileName = u.getFile(); 
        FileName = FileName.substring(FileName.lastIndexOf('/') + 1); 
        URLConnection uc = u.openConnection(); 
        int FileLenght = uc.getContentLength(); 
        if (FileLenght == -1) { 
           monView2.setText("Fichier non valide:"+ FileName); 
        } 

        try 
        { 
           InputStream myInput = uc.getInputStream(); 
           String outFileName = "/sdcard/GPTO/"+ NomParcours + "/" + FileName; 
           FileOutputStream myOutPut = new FileOutputStream(outFileName); 
           byte[]buff = new byte[1024]; 
           int l = myInput.read(buff); 

           while(l&gt;0) 
           { 
              myOutPut.write(buff, 0, l); 
              l = myInput.read(buff); 
           } 
           myOutPut.flush(); 
           myOutPut.close(); 
      } 
      catch(Exception e) 
      { 
         monView2.setText( e.toString()); 
      } 
 }
</code></pre>

<p>Please direct me in the right way, I am a beginner in Android and I  know just basics, what is the right way to achieve the same? </p>
