FTP implementation file upload (download)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.