It is not difficult to upload FTP files (including images) on the android client. Write it down to record it. Hope it will help new users.
Need to use commons-net-3.0.1.jar, followed by a jar package.
Directly run the Code:
/*** Upload a file through FTP * @ Param url ftp server address, for example, 192.168.1.110 * @ Param port, for example: 21 * @ Param username * @ Param Password * @ Param remotepath: Path to the FTP server disk * @ Param filenamepath: Path of the file to be uploaded * @ Param filename: name of the file to be uploaded *@ return */Public String ftpupload (string URL, string port, string username, string password, string remotepath, string filenamepath, string filename) {ftpclient = new ftpclient (); Fileinputstream FCM = NULL; string returnmessage = "0"; try {ftpclient. connect (URL, integer. parseint (port); Boolean loginresult = ftpclient. login (username, password); int returncode = ftpclient. getreplycode (); If (loginresult & ftpreply. ispositivecompletion (returncode) {// If the login is successful, ftpclient. makedirectory (remotepath); // sets the upload directory ftpclient. changeworkingdirectory (remotepath); ftpclient. setbuffer Size (1024); ftpclient. setcontrolencoding ("UTF-8"); ftpclient. enterlocalpassivemode (); FCM = new fileinputstream (filenamepath + filename); ftpclient. storefile (filename, FS); returnmessage = "1"; // uploaded successfully} else {// If logon fails returnmessage = "0" ;}} catch (ioexception E) {e. printstacktrace (); throw new runtimeexception ("FTP client error! ", E);} finally {// ioutils. closequietly (FCM); try {ftpclient. disconnect ();} catch (ioexception e) {e. printstacktrace (); throw new runtimeexception ("an exception occurred when closing the FTP connection! ", E) ;}} return returnmessage ;}
Jar package address: http://download.csdn.net/detail/baolong47/4096104
Turn: http://blog.csdn.net/baolong47/article/details/7301394