【问题标题】:jsch 0.1.55 throws java.io.IOException: End of IO Stream Readjsch 0.1.55 抛出 java.io.IOException: End of IO Stream Read
【发布时间】:2020-06-25 13:13:10
【问题描述】:

我们每天都在使用 jsch-0.1.53.jar 通过 SFTP 获取文件,但是在运行了几年后它现在停止工作了。我假设服务器管理员可能已经升级了服务器软件。

相关的代码(JAVA 1.7)并不意外:

            Hashtable<String, String> config = new Hashtable<String, String>();
            config.put("StrictHostKeyChecking", "no");
            sftpSession = jsch.getSession(user, host, port);
            sftpSession.setConfig(config);
            sftpSession.setPassword(password);
            sftpSession.connect();
            sftpChannel = (ChannelSftp) sftpSession.openChannel("sftp");
            sftpChannel.connect();

最后一行抛出“java.io.IOException: End of IO Stream Read”所以我猜是服务器关闭了连接。

我升级到 jsch 0.1.55(虽然下面的日志声称它是 0.1.54)但这并没有改变任何东西。

jsch 的日志输出如下:

*** Connecting to XXXXXXX.XXX.XX port 22
*** Connection established
*** Remote version string: SSH-2.0-7.9.0.0_openssh Globalscape
*** Local version string: SSH-2.0-JSCH-0.1.54
*** CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
*** aes256-ctr is not available.
*** aes192-ctr is not available.
*** aes256-cbc is not available.
*** aes192-cbc is not available.
*** CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
*** diffie-hellman-group14-sha1 is not available.
*** CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
*** SSH_MSG_KEXINIT sent
*** SSH_MSG_KEXINIT received
*** kex: server: diffie-hellman-group16-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
*** kex: server: ssh-rsa
*** kex: server: 3des-cbc,aes256-cbc,aes128-cbc,aes256-ctr,aes128-ctr
*** kex: server: 3des-cbc,aes256-cbc,aes128-cbc,aes256-ctr,aes128-ctr
*** kex: server: hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96
*** kex: server: hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96
*** kex: server: zlib,none
*** kex: server: zlib,none
*** kex: server: 
*** kex: server: 
*** kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
*** kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
*** kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
*** kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
*** kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
*** kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
*** kex: client: none
*** kex: client: none
*** kex: client: 
*** kex: client: 
*** kex: server->client aes128-ctr hmac-md5 none
*** kex: client->server aes128-ctr hmac-md5 none
*** SSH_MSG_KEX_DH_GEX_REQUEST(1024<1024<1024) sent
*** expecting SSH_MSG_KEX_DH_GEX_GROUP
*** Disconnecting from XXXXXXX.XXX.XX port 22

我试过了 config.setConfig("kex", "diffie-hellman-group1-sha1"); 这已在此处的类似问题中提出,但对我而言,这不适用于 0.1.53 和 0.1.55。

jcraft 提供的用于连接到 openSSH 的 jsch 示例也因相同的异常而失败。

我能够使用 WinSCP 使用相同的用户/密码连接到服务器。

是否有人能够根据日志提出解决方案(可能是正确的属性设置)?

非常感谢您的帮助。

【问题讨论】:

标签: java sftp jsch


【解决方案1】:

由于我在坚持使用 jsch 时无法解决这个问题,所以我重写了我们的通信层并将 jsch 替换为 sshj,这在我们的案例中非常容易。 对于遇到这个或类似 jsch 问题的人来说,这可能不是一个可行的解决方案,但对我们来说,它成功了。

【讨论】:

    猜你喜欢
    • 2015-10-03
    • 2021-02-17
    • 2016-09-13
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 2011-05-16
    相关资源
    最近更新 更多