0

SSHJ ライブラリを使用して複数のコマンドをデバイスに送信しようとしています。この形式で複数のコマンドを送信するオプションがあります。

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

これは機能しますが、私の場合は常に使用できるとは限りません。2番目の回答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

必要に応じて、接続先のデバイス、および接続先のデバイスの大部分がシスコのネットワーク機器であることに注意してください。

ご協力ありがとうございます。-ジャロッド

4

1 に答える 1

0

正確な問題の解決策は見つかりませんでした。しかし、DefaultPTY を使用し、送信したいすべてのデータを独自のストリームに提供することで、この問題を回避しました。この例で遊んでください。

于 2014-11-14T19:12:12.823 に答える