Ganymed SSH-2 for Java系列10之scpGet

来源:互联网 发布:网络监控布线图 编辑:程序博客网 时间:2024/05/16 14:35

 Ganymed SSH-2 for Java系列10之scpGet


直接上代码:

/** *  * 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();}}}

测试:


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下来了。





0 0
原创粉丝点击