我通过 ssh 连接到 unix 服务器并尝试执行“ls”命令并获取它的输出。代码是这样的
SessionChannelClient session = client.openSessionChannel();
session.startShell();
String cmd = "ls -l";
session.executeCommand(cmd);
ChannelInputStream in = session.getInputStream();
ChannelOutputStream out = session.getOutputStream();
IOStreamConnector input = new IOStreamConnector(System.in, session.getOutputStream());
IOStreamConnector output = new IOStreamConnector(session.getInputStream(), System.out);
运行后我没有在日志文件中得到任何输出。我发现通道请求失败,如图所示
1019 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol - 通道请求成功 1020 [main] INFO com.sshtools.j2ssh.session.SessionChannelClient - 请求命令执行 1021 [main] INFO com.sshtools.j2ssh.session.SessionChannelClient - 命令是 ls -l 1021 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol - 发送会话通道的 exec 请求 1021 [main] INFO com.sshtools.j2ssh.transport.TransportProtocolCommon - 发送 SSH_MSG_CHANNEL_REQUEST 1021 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol - 等待通道请求回复 1032 [传输协议 1] INFO com.sshtools.j2ssh.transport.TransportProtocolCommon - 收到 SSH_MSG_CHANNEL_EXTENDED_DATA 1033 [ssh-connection 1] 调试 com.sshtools.j2ssh.transport。服务 - 路由 SSH_MSG_CHANNEL_EXTENDED_DATA 1033 [ssh-connection 1] DEBUG com.sshtools.j2ssh.transport.Service - 已完成处理 SSH_MSG_CHANNEL_EXTENDED_DATA 1075 [传输协议 1] INFO com.sshtools.j2ssh.transport.TransportProtocolCommon - 收到 SSH_MSG_CHANNEL1FO INFAIL_com .sshtools.j2ssh.connection.ConnectionProtocol - 通道请求失败
为什么会这样?