【发布时间】:2013-12-20 13:52:19
【问题描述】:
我正在尝试使用 JSch 库执行一系列命令,一切都通过 SSH:
- "cd /root/downloads/"
- "wget mydownloadlink/file.rar"
- "scp -f 文件.rar"
但这不起作用,看看我的代码:
Channel channel = session.openChannel("exec");
//Enter in directory to download
String cdCommand ="cd /root/downloads/";
((ChannelExec) channel).setCommand(cdCommand);
//Execute wget command
String wgetCommand = "wget "+linkDownload;
((ChannelExec) channel).setCommand(wgetCommand);
// exec 'scp -f rfile' remotely
String command = "scp -f " + rfile;
((ChannelExec) channel).setCommand(command);
// get I/O streams for remote scp
OutputStream out = channel.getOutputStream();
InputStream in = channel.getInputStream();
channel.connect();
【问题讨论】:
-
你让它工作了吗?