JAVA program implementation file to Linux service upload and download __java

Source: Internet
Author: User
Tags ftp connection ftp client
Import Org.apache.commons.io.IOUtils;

Import org.apache.commons.net.ftp.FTPClient;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;

Import Java.io.FileOutputStream; /** * JAVA ftp upload Download Helper class * * Commons-net-1.4.1.jar pftclinet JAR Package * * @author: Jenminzhang * * public class Filemana
		gerbyftp {/** * FTP upload Single file test/public static void Fileuploadbyftp () {ftpclient ftpclient = new FtpClient ();

		FileInputStream FIS = null;
			try {ftpclient.connect ("192.85.1.9");

			Ftpclient.login ("Zhangzhenmin", "62672000");
			File Srcfile = new file ("E:\\test_back_081409.sql");
			FIS = new FileInputStream (srcfile);
			Set up the upload directory ftpclient.changeworkingdirectory ("/home/zhangzhenmin");
			Ftpclient.setbuffersize (1024);
			Ftpclient.setcontrolencoding ("GBK");
			Set file type (binary) ftpclient.setfiletype (ftpclient.binary_file_type);
		Ftpclient.storefile ("Test_back_081901.sql", FIS);
			catch (IOException e) {e.printstacktrace (); throw new RuntiMeexception ("FTP client error.)
		", e);
			finally {ioutils.closequietly (FIS);
			try {ftpclient.disconnect ();
				catch (IOException e) {e.printstacktrace (); throw new RuntimeException ("Shutdown FTP connection) exception occurred."
			", e);
		/** * FTP Downloads a single file test/public static void Filedownloadbyftp () {ftpclient ftpclient = new FtpClient ();

		FileOutputStream fos = null;
			try {ftpclient.connect ("192.85.1.9");

			Ftpclient.login ("Zhangzhenmin", "62672000");
			String remotefilename = "/home/zhangzhenmin/test_back_081901.sql";
			FOS = new FileOutputStream ("E:/test/test_back_081901.sql");
			FOS = new FileOutputStream ("H:/test/test_back_081901.sql");
			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 error.
		", e);
			Finally {ioutils.closequietly (FOS);
			try {ftpclient.disconnect (); }catch (IOException e) {e.printstacktrace (); throw new RuntimeException ("Shutdown FTP connection) exception occurred."
			", e);
		}} public static void Main (string[] args) {fileuploadbyftp ();
	Filedownloadbyftp ();
 }
}

Related Article

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.