0

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

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

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

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

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 网络设备。

感谢您提供任何帮助。-贾罗德

4

1 回答 1

0

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

于 2014-11-14T19:12:12.823 回答