FTP upload Download

Source: Internet
Author: User

/**
* FTP uploads individual files
*/
public static void Testupload () {
FtpClient ftpclient = new FtpClient ();
FileInputStream FIS = null;

try {
Ftpclient.connect ("192.168.1.208");
Ftpclient.login ("Ftp01", "123");

File Srcfile = new file ("C:\\ftp\\download\\noboktrd_20141006.txt");
FIS = new FileInputStream (srcfile);
Set upload directory settings
Ftpclient.changeworkingdirectory ("/test/f1");
Ftpclient.setbuffersize (1024*10);
Ftpclient.setcontrolencoding ("GBK");
Set file type (binary)
Ftpclient.setfiletype (Ftpclient.binary_file_type);
Ftpclient.storefile ("Noboktrd_20141006.txt", FIS);
} catch (IOException e) {
E.printstacktrace ();
throw new RuntimeException ("FTP client is wrong! ", e);
} finally {
ioutils.closequietly (FIS);
try {
Ftpclient.disconnect ();
} catch (IOException e) {
E.printstacktrace ();
throw new RuntimeException ("Close the FTP link is happening!! ", e);
}
}
}

/**
* FTP Download the single file
*/
public static void Testdownload () {
FtpClient ftpclient = new FtpClient ();
FileOutputStream fos = null;

try {
Ftpclient.connect ("192.168.1.208:2121");
Ftpclient.login ("Ftp01", "123");

String remotefilename = "/ftpdownload/noboktrd_20141006.txt";
FOS = new FileOutputStream ("C:\\ftp\\download\\noboktrd_20141006.txt");

Ftpclient.setbuffersize (1024);
Set file type (binary)
Ftpclient.setfiletype (Ftpclient.binary_file_type);
Ftpclient.retrievefile (Remotefilename, FOS);
} catch (IOException e) {
E.printstacktrace ();
throw new RuntimeException ("FTP client is wrong! ", e);
} finally {
ioutils.closequietly (FOS);
try {
Ftpclient.disconnect ();
} catch (IOException e) {
E.printstacktrace ();
throw new RuntimeException ("Close the FTP link is happening! ", e);
}
}
}

FTP 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.