Example code
PackageGeturlpic;ImportJava.io.ByteArrayInputStream;Importjava.io.IOException;ImportJava.io.InputStream;Importorg.apache.commons.net.ftp.FTPClient;ImportOrg.apache.commons.net.ftp.FTPFile;Importorg.apache.commons.net.ftp.FTPReply; Public classFtpuploadfile { Public Static voidMain (string[] args) {//Public Static Boolean uploadfile (String url,int port,string Username, string password, string path, String fi Lename, InputStream input) {//Boolean success = false;FtpClient FTP =Newftpclient (); InputStream input=NULL; Try { intreply; Ftp.connect ("localhost", 21);//connecting to an FTP server//If you use the default port, you can connect directly to the FTP server using Ftp.connect (URL)Ftp.login ("Test", "test");//LoginReply =Ftp.getreplycode (); if(!ftpreply.ispositivecompletion (Reply)) {Ftp.disconnect (); System.out.println ("Can not Connect");//return success;}Else{ftp.setfiletype (ftpclient.binary_file_type);//ftp.changeworkingdirectory (path);input =NewBytearrayinputstream ("Xuxxx". GetBytes ("Utf-8"))); Ftp.storefile ("Test.txt", input); //Create a directoryFtp.makedirectory ("/test/bb"); //List Directoryftpfile[] dirs = ftp.listdirectories ("/test"); for(Ftpfile f:dirs) {System.out.println (F.getname ()); } }//ftp.changeworkingdirectory (path);//ftp.storefile (filename, input); //input.close ();//ftp.logout ();//success = true;}Catch(IOException e) {e.printstacktrace (); } finally { if(Input! =NULL){ Try{input.close (); }Catch(IOException e) {e.printstacktrace (); } } if(ftp.isconnected ()) {Try{ftp.disconnect (); } Catch(IOException IoE) {}}}//return success; }// }}
Reference
Http://www.cnblogs.com/lucky_dai/p/6178076.html
Http://www.jb51.net/article/86367.htm
http://blog.csdn.net/kardelpeng/article/details/6588284
Https://zhidao.baidu.com/question/433380231.html
Https://zhidao.baidu.com/question/1387264816675112740.html
Http://www.jb51.net/article/86367.htm
FTP implementation file upload (download)