您的位置:首页 > 运维架构 > Linux

java模拟linux命令scp

2015-06-25 10:32 453 查看
要导入包ganymed-ssh2-build210.jar

package testScp;
import java.io.IOException;

import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SCPClient;

public class Scp {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String user = "root";
String pass = "`12345678qwer";
String host = "192.168.2.2";

Connection con = new Connection(host);
try {
con.connect();
boolean isAuthed = con.authenticateWithPassword(user, pass);
System.out.println("isAuthed===="+isAuthed);
SCPClient scpClient = con.createSCPClient();
scpClient.put("F:\\path.txt", "/root/"); //从本地复制文件到远程目录
System.out.println("成功传输!");
}catch (IOException e) {
e.printStackTrace();
}
con.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: