读书人

java 复制远路linux上的文件

发布时间: 2013-08-04 18:26:15 作者: rapoo

java 复制远程linux上的文件
遇到这个问题,不知道应该怎么实现?
我自己在弄了一个demo,但是出错了,希望能够得到答复,谢谢。
我的demo:


SshWrapper ssh = new SshWrapper();

try {
ssh.connect(IP, portNum);
ssh.login(uid, pwd);
ssh.waitfor("$");

System.out.println(ssh.send("cd /home"));

System.out.println(ssh.send("ls -l"));

ssh.disconnect();
} catch (java.io.IOException e) {
e.printStackTrace();
}

问题:
ssh.connect(IP, portNum); 执行通过
ssh.login(uid, pwd); 执行通过
ssh.waitfor("$"); 执行通过
在ssh.send("cd /home")返回null,
在ssh.send("ls -l")返回null,
我确定在远程主机上有/home目录。
谢谢
[解决办法]
http://javatelnet.org/download/source/de/mud/ssh/SshWrapper.html

The telnet ssh is a sample class for how to use the SSH protocol handler of the JTA source package. To write a program using the wrapper you may use the following piece of code as an example:

SshWrapper telnet = new SshWrapper();
try {
ssh.connect(args[0], 23);


ssh.login("user", "password");
ssh.setPrompt("user@host");
ssh.waitfor("Terminal type?");
ssh.send("dumb");
System.out.println(ssh.send("ls -l"));
} catch(java.io.IOException e) {
e.printStackTrace();
}

读书人网 >J2SE开发

热点推荐