Ganymed SSH-2 for Java系列10之scpGet
2014-04-18 16:05
246 查看
Ganymed SSH-2 for Java系列10之scpGet
直接上代码:
[java]
view plaincopy
/**
*
* Get remote file through scp
*
* @param host
*
* @param username
*
* @param password
*
* @param remoteFile
*
* @param localDir
*
* @throws IOException
*/
public static void scpGet(String host, String username, String password,
String remoteFile, String localDir, int port) throws IOException {
if (logger.isInfoEnabled()) {
logger.info("spc [" + remoteFile + "] from " + host + " to "
+ localDir);
}
Connection conn = null;
try {
conn = getOpenedConnection(host, username, password, port);
SCPClient client = new SCPClient(conn);
client.get(remoteFile, localDir);
} finally {
if (null != conn) {
conn.close();
}
}
}
测试:
[java]
view plaincopy
String remoteDir = "/usr/local/test.log";
String localFile ="src/";
try {
CommandRunner.scpGet("172.16.18.141", "root",
"123456", remoteDir,localFile, 22);
} catch (IOException e) {
e.printStackTrace();
}
通过查看src目录下面,发现文件已经get下来了。
直接上代码:
[java]
view plaincopy
/**
*
* Get remote file through scp
*
* @param host
*
* @param username
*
* @param password
*
* @param remoteFile
*
* @param localDir
*
* @throws IOException
*/
public static void scpGet(String host, String username, String password,
String remoteFile, String localDir, int port) throws IOException {
if (logger.isInfoEnabled()) {
logger.info("spc [" + remoteFile + "] from " + host + " to "
+ localDir);
}
Connection conn = null;
try {
conn = getOpenedConnection(host, username, password, port);
SCPClient client = new SCPClient(conn);
client.get(remoteFile, localDir);
} finally {
if (null != conn) {
conn.close();
}
}
}
测试:
[java]
view plaincopy
String remoteDir = "/usr/local/test.log";
String localFile ="src/";
try {
CommandRunner.scpGet("172.16.18.141", "root",
"123456", remoteDir,localFile, 22);
} catch (IOException e) {
e.printStackTrace();
}
通过查看src目录下面,发现文件已经get下来了。
相关文章推荐
- Ganymed SSH-2 for Java系列10之scpGet
- Ganymed SSH-2 for Java系列11之SCPClient
- Ganymed SSH-2 for Java系列9之scpPut
- Ganymed SSH-2 for Java系列11之SCPClient
- Ganymed SSH-2 for Java系列9之scpPut
- Ganymed SSH-2 for Java系列4之删除远程服务器上的文件
- Ganymed SSH-2 for Java系列5之删除远程服务器上的目录(补充说明)
- Ganymed SSH-2 for Java系列1之 ganymed-ssh2介绍
- Ganymed SSH-2 for Java系列6之删除远程服务器上的非空目录
- Ganymed SSH-2 for Java系列3之执行远程shell 命令
- Ganymed SSH-2 for Java系列7之删除远程服务器上的非空目录(方法说明)
- Ganymed SSH-2 for Java系列4之删除远程服务器上的文件
- Ganymed SSH-2 for Java系列5之删除远程服务器上的目录
- Ganymed SSH-2 for Java系列1之 ganymed-ssh2介绍
- Ganymed SSH-2 for Java系列6之删除远程服务器上的非空目录
- Ganymed SSH-2 for Java系列5之删除远程服务器上的目录(补充说明)
- Ganymed SSH-2 for Java系列7之删除远程服务器上的非空目录(运用执行shell脚本的方式)
- Ganymed SSH-2 for Java系列7之删除远程服务器上的非空目录(运用执行shell脚本的方式)
- Ganymed SSH-2 for Java系列3之执行远程shell 命令
- Ganymed SSH-2 for Java系列5之删除远程服务器上的目录