Pom文件中引入jar
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>build210</version>
</dependency>
//文件scp到数据服务器
Connection conn = new Connection(“192.168.1.1”);
try {
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(“linux帐户”, “linux密码”);
if (isAuthenticated == false){
throw new IOException(SmartoNetTipsMessage.NginxNotFound.getZhText());
}
SCPClient client = new SCPClient(conn);
client.put(“本地路径”, “linux路径”); //反过来写就是从linux复制到本地
} catch (IOException e) {
e.printStackTrace();
throw new IOException(e.toString());
}finally {
conn.close();
}