/**
* 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