jsch0.1.55连接报错 Caught an exception, leaving main loop due to End of IO Stream Re

1,730 阅读1分钟

今天发现jsch sftp连接成功后还是在cd路径时报错,

Caused by: java.io.IOException: inputstream is closed

发现jsch在登录成功后自己打出的信息

 Caught an exception, leaving main loop due to End of IO Stream Read

连接在抛出这个问题后就被关闭了。所以cd时说流已经被关闭了 具体报错信息如下

SftpUtil: kex: client: none
SftpUtil: kex: client: none
SftpUtil: kex: client:
SftpUtil: kex: client:
SftpUtil: kex: server->client aes128-ctr hmac-md5 none
SftpUtil: kex: client->server aes128-ctr hmac-md5 none
SftpUtil: SSH_MSG_KEX_ECDH_INIT sent
SftpUtil: expecting SSH_MSG_KEX_ECDH_REPLY
SftpUtil: ssh_rsa_verify: signature true
SftpUtil: Permanently added 'gw.open.icbc.com.cn' (RSA) to the list of known hosts.
SftpUtil: SSH_MSG_NEWKEYS sent
SftpUtil: SSH_MSG_NEWKEYS received
SftpUtil: SSH_MSG_SERVICE_REQUEST sent
SftpUtil: SSH_MSG_SERVICE_ACCEPT received
SftpUtil: Authentications that can continue: publickey,keyboard-interactive,password
SftpUtil: Next authentication method: publickey
SftpUtil: Authentication succeeded (publickey).
SftpUtil: 用户[qdgxwt]成功登录
SftpUtil: Caught an exception, leaving main loop due to End of IO Stream Read
SftpUtil: Disconnecting from gw.open.icbc.com.cn port 8001
Caused by: 4:
        at com.jcraft.jsch.ChannelSftp.getHome(ChannelSftp.java:2443)
        at com.jcraft.jsch.ChannelSftp.getCwd(ChannelSftp.java:2452)
        at com.jcraft.jsch.ChannelSftp.remoteAbsolutePath(ChannelSftp.java:2944)
        at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:339)
        at com.asiainfo.aisports.tools.sftp.SftpUtil.cd(SftpUtil.java:117)
        ... 22 more
Caused by: java.io.IOException: inputstream is closed
        at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2911)
        at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2935)
        at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2355)
        at com.jcraft.jsch.ChannelSftp.getHome(ChannelSftp.java:2437)

在stackoverflow上查到了解决方法,具体地址如下stackoverflow.com/questions/3…

答案说从0.1.53 版本开始,连接时更加青睐于diffie-hellman-group-exchange-sha256, jsch尝试使用这个kex,但是这样因为一些原因会被服务器关闭了连接,可以强制在建立连接时使用 diffie-hellman-group1-sha1 ,设置方法如下

session.setConfig("kex", "diffie-hellman-group1-sha1"); 

原文如下:

The JSch 0.1.53 supports (and prefers) the diffie-hellman-group-exchange-sha256 KEX, what the server claims to support too, so the JSch tries to use it.

For some reason the server disconnects you afterwards.

To workaround that, force the JSch to use the diffie-hellman-group1-sha1 KEX, what the JSch 0.1.52 prefers:

session.setConfig("kex", "diffie-hellman-group1-sha1");