Ganymed SSH-2 for Java series 9 Scpput__java

Source: Internet
Author: User
Tags ssh ssh port

Ganymed SSH-2 for Java Series 8 Scpput


/**
	 * * Put the local 
	 file to remote machine.
	 * * 
	 @param host
	 * * 
	 @param username * * @param password * * 
	 @param localfile 
	 * * @param remotedir
	 * 
	 * @throws ioexception

	/public static void Scpput (string host, String username, String password,

	string localfile, String Remotedir, string permissions_code, int port)
			throws IOException { C18/>if (logger.isinfoenabled ()) {

			logger.info ("SCP [" + LocalFile +] to "+ host + Remotedir);

		}

		Connection conn = null;

		try {
			conn = getopenedconnection (host, username, password, port);

			Scpclient client = new Scpclient (conn);

			Client.put (LocalFile, Remotedir, Permissions_code);
		} Finally {
			if (NULL!= conn) {
				conn.close ();
			}
		}

	}

Description of each parameter:

String Host Server IP

String Username User Name

String Password, password

String LocalFile, local file

String remotedir, remote directory

String Permissions_code, permission code

int port SSH Port


Example:

	String Remotedir = "/usr/local";
		String LocalFile = "Src/test.log";

		try {

			commandrunner.scpput ("172.16.18.141", "root",
					"123456", LocalFile, Remotedir, "0060");
			
		IOException e) {
			e.printstacktrace ();
		}

Description

This operation is to upload the local test.log to the remote directory: USR the directory below, if repeated upload the same file, will overwrite the previous file,

If the first given permission code is 0060, upload the same file, the second given the permission code is 0600, then its permissions will not be changed,

But the file will be overwritten by the second uploaded file.



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.