SSHJ 通道在完成输入流之前关闭

问题描述

图书馆:

  1. SshJ
  2. 期待

基本上,尝试通过 ssh 连接到 BNG 以检索某些值。在 Juniper Junos 上运行时有一定的 cmd 写入前关闭 cmd 输入流。

代码片段:

private void setup() throws IOException {
    DefaultConfig defaultConfig = new DefaultConfig();
    defaultConfig.setKeepAliveProvider(KeepAliveProvider.HEARTBEAT);
    ssh = new SSHClient(defaultConfig);
    ssh.addHostkeyverifier(
            (s,i,publicKey) -> true);
    ssh.connect(param.getHost(),param.getPort());
    ssh.authPassword(param.getUsername(),param.getpassword());
    session = ssh.startSession();
    session.allocateDefaultPTY();
    Shell shell = session.startShell();
    expect = new ExpectBuilder()
            .withOutput(shell.getoutputStream())
            .withInputs(shell.getInputStream(),shell.getErrorStream())
            .withEchoInput(System.out)
            .withEchoOutput(System.err)
            .withInputFilters(removeColors(),removeNonPrintable())
            .withExceptionOnFailure()
            .build();
}

然后采样调用

expect.sendLine("set cli screen-length 0");
expect.expect(contains(PROMPT));

String cmd = String.format("show configuration routing-instances | match %s | display set",xxx.123);
expect.sendLine(cmd);

log.info(expect.expect(contains(PROMPT)).getBefore().trim());

从 DEBUG 记录器中,通道在写入流之前关闭

[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 29 down to 2088701
disabling complete-on-space
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 2 down to 2088699

[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 10 down to 2088689
{master}
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 37 down to 2088652
user@host>> [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote  - Consuming by 69 down to 2096791
show configuration routing-instances | match ae13.1304 | display set
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 4 down to 2088648
show[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 14 down to 2088634
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 17 down to 2088617
 configuration[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 1 down to 2088616
 routing-instances[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 101 down to 2088515
user@host>> ...ing-instances |[main] INFO  org.example.device  - show configuration routing-instances
[main] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel  - Sending close
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 6 down to 2088509
[main] DEBUG net.schmizz.concurrent.Promise  - Awaiting <<chan#0 / close>>
[reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel  - Got chan request for `exit-signal`
[reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel  - Got close
[reader] DEBUG net.schmizz.sshj.connection.ConnectionImpl  - Forgetting `session` channel (#0)
[reader] DEBUG net.schmizz.concurrent.Promise  - Setting <<chan#0 / close>> to `SOME`
[main] INFO  net.schmizz.sshj.transport.TransportImpl  - disconnected - BY_APPLICATION

在将 cmd 传递给服务器之前,感谢任何提示为什么通道关闭。尝试保持热拍,但目前没有结果。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)