JSch 的 SFTP 连接错误:SSH_MSG_DISCONNECT:11 内部服务器错误

SFTP connection error with JSch: SSH_MSG_DISCONNECT: 11 Internal server error

我试图从 SFTP 服务器检索文件 - 连接到此 SFTP 时使用 FileZilla - SFTP 方法。

对于 JSch,我已经使用 JSch 尝试了这段代码

JSch jsch = new JSch();
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
config.put("PreferredAuthentications", "password");
Session session = jsch.getSession( "super_robot", "192.192.192.com", 6222 );
session.setConfig(config );
session.setPassword( "a1234!X@" );
session.connect( 30000 );

虽然我得到了这个错误:

Caused by: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 Internal server error. 
    at com.jcraft.jsch.Session.read(Session.java:1004)
    at com.jcraft.jsch.Session.connect(Session.java:323)

对于StandardFileSystemManager我也有同样的错误:

SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, connectionTimeout);
SftpFileSystemConfigBuilder.getInstance().setIdentityInfo(opts);

SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
StandardFileSystemManager fsManager = new StandardFileSystemManager();
fsManager.init();

遇到这个错误:

Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "digital.crossix.com".
    at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:147)
    at org.apache.commons.vfs2.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:79)
    ... 40 more
Caused by: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 Internal server error. 
    at com.jcraft.jsch.Session.read(Session.java:1004)
    at com.jcraft.jsch.Session.connect(Session.java:323)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:145)
    ... 41 more

我尝试了这些链接中提供的其他解决方案,但没有解决问题:

请注意,这些错误中的 none 与我面临的错误完全相同 - 它们有点相似。 没有找到与我所面临的错误完全相同的人。

当我使用 FileZilla 时,这是我在控制台中看到的日志:

Status: Connecting to 192.192.com:6222...
Trace:  CControlSocket::SendNextCommand()
Trace:  CSftpConnectOpData::Send() in state 0
Trace:  Going to execute C:\Program Files\FileZilla FTP Client\fzsftp.exe
Response:   fzSftp started, protocol_version=8
Trace:  CSftpConnectOpData::ParseResponse() in state 0
Trace:  CControlSocket::SendNextCommand()
Trace:  CSftpConnectOpData::Send() in state 3
Command:    open "super_robot@192.192.com" 6222
Trace:  Connecting to 192.192.194 port 6222
Trace:  We claim version: SSH-2.0-FileZilla_3.30.0
Trace:  Server version: SSH-2.0-NuaneSSH_0.8.1.0
Trace:  Using SSH protocol version 2
Trace:  Doing Diffie-Hellman group exchange
Trace:  Doing Diffie-Hellman key exchange with hash SHA-1
Trace:  Server also has ssh-dss host key, but we don't know it
Trace:  Host key fingerprint is:
Trace:  ssh-rsa 1024 ------------------------------------
Command:    Trust new Hostkey: Once
Trace:  Initialised AES-256 CBC client->server encryption
Trace:  Initialised HMAC-SHA1 client->server MAC algorithm
Trace:  Initialised AES-256 CBC server->client encryption
Trace:  Initialised HMAC-SHA1 server->client MAC algorithm
Trace:  Attempting keyboard-interactive authentication
Trace:  Using keyboard-interactive authentication. inst_len: 0, num_prompts: 1
Command:    Pass: ********
Trace:  Access granted
Trace:  Opening session as main channel
Trace:  Opened main channel
Trace:  Started a shell/command
Status: Connected to 192.192.com
Trace:  CSftpConnectOpData::ParseResponse() in state 3
Trace:  CControlSocket::ResetOperation(0)
Trace:  CSftpConnectOpData::Reset(0) in state 3
Trace:  CFileZillaEnginePrivate::ResetOperation(0)
Status: Retrieving directory listing...
Trace:  CControlSocket::SendNextCommand()
Trace:  CSftpListOpData::Send() in state 0
Trace:  CSftpChangeDirOpData::Send() in state 0
Trace:  CSftpChangeDirOpData::Send() in state 1
Command:    pwd
Response:   Current directory is: "/"
Trace:  CSftpChangeDirOpData::ParseResponse() in state 1
Trace:  CControlSocket::ResetOperation(0)
Trace:  CControlSocket::ParseSubcommandResult(0)
Trace:  CSftpListOpData::SubcommandResult() in state 1
Trace:  CControlSocket::SendNextCommand()
Trace:  CSftpListOpData::Send() in state 2
Trace:  CSftpListOpData::Send() in state 3
Command:    ls
Status: Listing directory /
Trace:  CSftpListOpData::ParseResponse() in state 3
Trace:  CControlSocket::ResetOperation(0)
Status: Directory listing of "/" successful
Trace:  CFileZillaEnginePrivate::ResetOperation(0)

我该怎么做才能解决这个错误?

同时附上来自 JSch 的日志

INFO: Connection established
INFO: Remote version string: SSH-2.0-NuaneSSH_0.8.1.0
INFO: Local version string: SSH-2.0-JSCH-0.1.54
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
INFO: kex: server: ssh-rsa,ssh-dss
INFO: kex: server: aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc
INFO: kex: server: aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc
INFO: kex: server: hmac-sha1,hmac-md5
INFO: kex: server: hmac-sha1,hmac-md5

INFO: kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
INFO: kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96

INFO: kex: server->client aes128-cbc hmac-md5 none
INFO: kex: client->server aes128-cbc hmac-md5 none
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: Disconnecting from 192.192.com port 6222

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65)
Caused by: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 Internal server error. 
    at com.jcraft.jsch.Session.read(Session.java:1004)
    at com.jcraft.jsch.Session.connect(Session.java:323)
    at com.xxxxxxx.yyyy.service.SFTPTest.main(SFTPProviderTest.java:50)
    ... 5 more

似乎是服务器上的错误或问题。检查 server-side 日志文件。

但请注意,FileZilla 使用 "AES-256 CBC" 成功连接。您的 JSch 代码仅使用 "AES-128 CBC",因为 "AES-256 CBC" 不可用。

尝试安装 JCE 以启用 "AES-256 CBC"。参见

缺少此配置,但有了它,我能够连接

Properties config = new Properties();
config.put("kex","diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1");

并记录:

INFO: kex: server->client aes128-cbc hmac-md5 none
INFO: kex: client->server aes128-cbc hmac-md5 none
INFO: SSH_MSG_KEX_DH_GEX_REQUEST(1024<2048<2048) sent
INFO: expecting SSH_MSG_KEX_DH_GEX_GROUP
INFO: SSH_MSG_KEX_DH_GEX_INIT sent
INFO: expecting SSH_MSG_KEX_DH_GEX_REPLY
INFO: ssh_rsa_verify: signature true
WARN: Permanently added '192.192.com' (RSA) to the list of known hosts.
INFO: SSH_MSG_NEWKEYS sent
INFO: SSH_MSG_NEWKEYS received
INFO: SSH_MSG_SERVICE_REQUEST sent
INFO: SSH_MSG_SERVICE_ACCEPT received
INFO: Authentications that can continue: password
INFO: Next authentication method: password
INFO: Authentication succeeded (password).