【发布时间】: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 使用相同的用户/密码连接到服务器。
是否有人能够根据日志提出解决方案(可能是正确的属性设置)?
非常感谢您的帮助。
【问题讨论】:
-
@Martin:感谢您的提示,但升级到 openJDK 1.8.252 并没有改变任何东西。