使用 Apache VFS 时如何在 JSch Session 上设置 KEX

How to set KEX on JSch Session when using Apache VFS

我正在使用 Apache VFS 2.1JSch 0.1.54(今天的最新版本)使用 SFTP 上传文件。

连接时系统抛出"End of IO Stream Read",完整堆栈为:

Caused by: com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read
    at com.jcraft.jsch.Session.connect(Session.java:565)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:166)

我在 中找到了解决我的问题的可能方法,但它直接与 JSch 一起运行。因为我使用的是 Apache VFS,所以我无法直接访问 Session(至少我认为我不能)。

但如果可以的话,它看起来像这样:

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

查看 Apache VFS 实现 org.apache.commons.vfs2.provider.sftp.SftpClientFactory 它没有找到设置此 属性 的方法。

如何使用 Apache VFS 设置此配置 API?

更新

日志数据:

22/05/2017 09:27:20 org.apache.commons.vfs2.impl.StandardFileSystemManager info
INFO: Using "D:\Users\TECBMEPI\AppData\Local\Temp\vfs_cache" as temporary files store.
22/05/2017 09:27:20 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Connecting to z1t1brmxpta022 port 22
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Connection established
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Remote version string: SSH-2.0-OpenSSH_6.6.1
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Local version string: SSH-2.0-JSCH-0.1.54
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes256-ctr is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes192-ctr is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes256-cbc is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes192-cbc is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: diffie-hellman-group14-sha1 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdh-sha2-nistp256 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdh-sha2-nistp384 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdh-sha2-nistp521 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdsa-sha2-nistp256 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdsa-sha2-nistp384 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdsa-sha2-nistp521 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: SSH_MSG_KEXINIT sent
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: SSH_MSG_KEXINIT received
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: none,zlib@openssh.com
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: none,zlib@openssh.com
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: ssh-rsa,ssh-dss
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server->client aes128-ctr hmac-md5 none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client->server aes128-ctr hmac-md5 none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: SSH_MSG_KEX_DH_GEX_REQUEST(1024<1024<1024) sent
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: expecting SSH_MSG_KEX_DH_GEX_GROUP
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Disconnecting from z1t1brmxpta022 port 22

JSch Session 从其 JSch 实例继承设置。所有 JSch 个实例实际上共享相同的 global/static 哈希表和设置。

所以只需在 SftpClientFactory.createConnection:

之前调用 static JSch.setConfig
JSch.setConfig("kex", "diffie-hellman-group1-sha1");