【问题标题】:Executing wget in remote server with JSch使用 JSch 在远程服务器中执行 wget
【发布时间】:2013-12-20 13:52:19
【问题描述】:

我正在尝试使用 JSch 库执行一系列命令,一切都通过 SSH:

  1. "cd /root/downloads/"
  2. "wget mydownloadlink/file.rar"
  3. "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();

【问题讨论】:

  • 你让它工作了吗?

标签: java jsch


【解决方案1】:

channel.connect() 正在执行您提供给它的最后一个命令。您需要为要运行的每个命令创建一个新的通道 exec/connect。您还应该打开/检索错误流,因为在这种情况下它可能会显示错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-17
    • 2015-11-17
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2014-01-04
    相关资源
    最近更新 更多