![](/img/trans.png)
[英]Executing ssh on remote server to jump to another server and execute further commands there using Java and JSch
[英]Executing wget in remote server with JSch
我正在尝试使用JSch库执行命令序列,所有步骤都经过SSH:
但这不起作用,请放心我的代码:
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();
channel.connect()
正在执行您提供给它的最后一个命令。 您需要为要运行的每个命令创建一个新的通道exec / connect。 您还应该打开/检索错误流,因为在这种情况下它可能显示了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.