//数据服务器的ip地址
private String dataServerIp = "192.168.123.123";
//数据服务器的用户名
private String dataServerUsername = "root";
//数据服务器的密码
private String dataServerPassword = "1234";
//数据服务器的目的文件夹
private String dataServerDestDir = "/export/App/uploadDir/";
//从远程到本地的保存路径
// private String localDir = "D:\\上传文件的临时目录";
//文件scp到数据服务器
Connection conn = new Connection(dataServerIp);
log.info("开始scp文件");
try {
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(dataServerUsername, dataServerPassword);
if (isAuthenticated == false)
throw new IOException("Authentication failed.文件scp到数据服务器时发生异常");
SCPClient client = new SCPClient(conn);
client.put("D:\\00审计.zip", dataServerDestDir); //本地文件scp到远程目录
// client.get(dataServerDestDir + "00审计.zip", localDir);//远程的文件scp到本地目录
conn.close();
} catch (IOException e) {
e.printStackTrace();
log.error("文件scp到数据服务器时发生异常");
}
log.info("scp文件结束");
<!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 -->
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>build210</version>
</dependency>
欢迎关注公众号:
还没有评论,来说两句吧...