【问题标题】:Sending Multiple Commands to device Through SSH通过 SSH 向设备发送多个命令
【发布时间】:2018-01-25 02:19:19
【问题描述】:

我正在尝试使用 SSHJ 库向设备发送多个命令。可以选择以这种格式发送多个命令:

Command command = sshSession.exec("show line; show ip interface brief;");

这可行,但在我的情况下并不总是可用。我找到了其他建议,例如第二个答案here

当我尝试这个建议时,第一个命令工作正常,然后它在这个错误之间循环:

net.schmizz.sshj.connection.ConnectionException: Broken transport; encountered EOF
...
Caused by: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF

Exception in thread "main" java.lang.IllegalStateException: Not connected
at net.schmizz.sshj.SSHClient.checkConnected(SSHClient.java:713)
at net.schmizz.sshj.SSHClient.startSession(SSHClient.java:651)

使用的代码是:

sshSession = sshClient.startSession();
Command command = sshSession.exec("sho ip int brie");
System.out.println(IOUtils.readFully(command.getInputStream()));//Just to see the reply while testing
command.join(5, TimeUnit.SECONDS);

sshSession = sshClient.startSession();
Command command2 = sshSession.exec("sho line");
System.out.println(IOUtils.readFully(command2.getInputStream()));//Just to see the reply while testing

如果需要,请备注我正在连接的设备以​​及它将连接到的大多数设备是 Cisco 网络设备。

感谢您的帮助。 -贾罗德

【问题讨论】:

    标签: java ssh sshj


    【解决方案1】:

    从未找到确切问题的解决方案。但是我通过使用 DefaultPTY 并为我自己的流提供了我想要发送的所有数据来解决这个问题。玩弄this 示例。

    【讨论】:

    • 你能发布代码的相关部分吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    相关资源
    最近更新 更多