how to connect to ftp server from android -


i have gone through many discussion uploading file ftp server.i think there 2 ways connect , upload:

1: must use apache library , use classes ftpclient.

2: urlconnection 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>0)             {                myoutput.write(buff, 0, l);                l = myinput.read(buff);             }             myoutput.flush();             myoutput.close();        }        catch(exception e)        {           monview2.settext( e.tostring());        }   } 

please direct me in right way, beginner in android , know basics, right way achieve same?

ftpclient.connect(inetaddress.getbyname(server)); ftpclient.login(user, password); ftpclient.changeworkingdirectory(serverroad); ftpclient.setfiletype(ftp.binary_file_type); bufferedinputstream buffin=null; buffin=new bufferedinputstream(new fileinputstream(file)); ftpclient.enterlocalpassivemode(); ftpclient.storefile("mysampletext.txt", buffin); buffin.close(); ftpclient.logout(); ftpclient.disconnect(); 

use code after importing ftp library. link


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -