我正在使用Apache VFS 2.1
与JSch 0.1.54
(今天的最新版本)使用SFTP上传文件。
系统在连接时抛出" IO流读取结束" ,完整堆栈为:
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)
我在this thread找到了解决问题的可能方法,但它直接使用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
答案 0 :(得分:2)
JSch Session
从其JSch
实例继承设置。并且所有JSch
实例实际上都与设置共享相同的全局/静态哈希表。
所以只需在SftpClientFactory.createConnection
之前调用静态JSch.setConfig
:
JSch.setConfig("kex", "diffie-hellman-group1-sha1");