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.