You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Jsch连接AWS SFTP服务器时抛出NullPointerException异常

连接AWS SFTP服务器时JSch握手后立即断开并抛出空指针异常

环境信息

  • 使用的JSch版本:implementation group: 'com.github.mwiede', name: 'jsch', version: '0.2.11'

报错信息

com.jcraft.jsch.JSchException: java.lang.NullPointerException
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:605)

连接代码

try{
    Security.insertProviderAt(new BouncyCastleProvider(), 1);

    Hashtable<String, String> config = new Hashtable<>();
    config.put("StrictHostKeyChecking", "no");

    JSch sch = new JSch();
    JSch.setConfig(config);
    JSch.setLogger(new TestLogger(logger));

    JSch.setConfig("kex", "diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256");
    JSch.setConfig("mac.s2c", "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com");
    JSch.setConfig("mac.c2s", "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com");

    JSch.setConfig("enable_server_sig_algs", "yes");
    JSch.setConfig("prefer_known_host_key_types", "yes");
    JSch.setConfig("PubkeyAcceptedAlgorithms", "ssh-rsa");

    Session session = sch.getSession(username, hostname, 22);

    System.out.println("Opening session for SFTP");
    sch.addIdentity(rsaKey);

    System.out.println("Attempting to connect");
    session.connect(60 * 1000);

}catch (Exception e){
    System.out.println("Error: " + e);
}

连接日志

Attempting to connect
INFO | Connecting to HOSTNAME port PORT
INFO | Connection established
INFO | Remote version string: SSH-2.0-AWS_SFTP_1.1
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
CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
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-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
INFO | kex: server: rsa-sha2-512,rsa-sha2-256,ssh-rsa
INFO | kex: server: aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr
INFO | kex: server: aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr
INFO | kex: server: hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com
INFO | kex: server: hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com
INFO | kex: server: none,zlib@openssh.com
INFO | kex: server: none,zlib@openssh.com
INFO | kex: server: 
INFO | kex: server: 
INFO | kex: client: diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
INFO | kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO | kex: client: aes192-ctr
INFO | kex: client: aes192-ctr
INFO | kex: client: hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com
INFO | kex: client: hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com
INFO | kex: client: none
INFO | kex: client: none
INFO | kex: client: 
INFO | kex: client: 
INFO | kex: server->client aes192-ctr hmac-sha2-256-etm@openssh.com none
INFO | kex: client->server aes192-ctr hmac-sha2-256-etm@openssh.com none
INFO | Disconnecting from HOSTNAME port PORT

内容的提问来源于stack exchange,提问作者greatFritz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 01:30:56