Java:ftp Uploading Files

Source: Internet
Author: User

public class ftpupload {    private ftpclient client;     /**     *  connect the FTP server and change the path of the selected FTP server      *       */    public void connect (FtpConfig config)  throws SocketException, IOException {         Client = new ftpclient ();         client.connect ( Config.getserver (),  config.getport ());//Set FTP server address and Port          Client.login (Config.getusername (),  config.getpassword ());//Set server user and password          int reply = client.getreplycode ();         if  (! Ftpreply.ispositivecompletion (Reply))              Client.disconnect ();         client.changeworkingdirectory (Config.getRemotePath ());         client.setfiletransfermode (FTP. Binary_file_type);         client.setfiletype (FTP. Binary_file_type)     }    /**    * Close connection      */    public void closeconnect ()  {         try {             this.client.disconnect ();        } catch  (IOException  e)  {            e.printstacktrace ();         }    }             /**      * Changing the work of FTP dir      */    public void changedirector (String  path)  throws Exception {        String  Pathtree[] = path.split ("\ \" +file.separator);         for   (int i = 0; i < pathtree.length; i++)  {             if  (Stringutil.nonullblank (pathtree[i))  {                  if  (!client.changeworkingdirectory (pathtree[i))  {                      client.makedirectory (PathTree[i]);                       client.changeworkingdireCtory (Pathtree[i]);                  }             }         }    }    /**      *  upload the specified file or directory to the server      */    public void upfile (File file)  throws Exception {        if  ( File.isdirectory ())  {             Client.makedirectory (File.getname ());             Client.changeworkingdirectory (File.getname ());             file[] files = file.listfiles ();             for  (FilE row : files)                  upfile (Row);            }  else {            file infile =  new file (File.getpath ());             Fileinputstream input = new fileinputstream (InFile);             client.storefile (New string (Infile.getname () getBytes ("GBK"), " Iso-8859-1 "),  input);             input.close ( );         }    }}

This article from the "Job" blog, reproduced please contact the author!

Java:ftp Uploading Files

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.