ssh2-sftp-client: Timed out while waiting for handshake

I have set redyTimeout to 99999, but it still connects time out. I use sftp on the command line, it works to connect my host. Please some suggestions on how can I process it. Thanks.

  • nodejs version: v12.16.0
  • ssh2-sftp-client version: 6.13.4
  • OS: macOS Mojave 10.14.6

this is code

const SftpClient = require("ssh2-sftp-client");

const sftp = new SftpClient();
sftp.connect({
    host: config.sftpHost,
    port: config.sftpPort,
    username: config.sftpID,
    password: config.sftpPW,
    protocol: "sftp",
    readyTimeout: 99999,
    debug: console.log,
    algorithms: {
        kex: [
            "diffie-hellman-group1-sha1",
            "ecdh-sha2-nistp256",
            "ecdh-sha2-nistp384",
            "ecdh-sha2-nistp521",
            "diffie-hellman-group-exchange-sha256",
            "diffie-hellman-group14-sha1"
        ],
        cipher: [
            "3des-cbc",
            "aes128-ctr",
            "aes192-ctr",
            "aes256-ctr",
            "aes128-gcm",
            "aes128-gcm@openssh.com",
            "aes256-gcm",
            "aes256-gcm@openssh.com",
            "aes256-cbc"
        ],
        serverHostKey: [
            "ssh-rsa",
            "ssh-dss",
            "ecdsa-sha2-nistp256",
            "ecdsa-sha2-nistp384",
            "ecdsa-sha2-nistp521"
        ],
        hmac: ["hmac-sha2-256", "hmac-sha2-512", "hmac-sha1"]
    }
})
    .then(() => {
        console.log("connect SFTP!!");
        return sftp.list("/");
       // return sftp.get(remotePath, dst))
    })
    .then(() => {
        console.log("connect SFTP!!");
        sftp.end();
    })
    .catch(err => {
        console.error(err.message);
    });

this is debug log

Protocol.js:125
Handshake: S->C compression: none
Protocol.js:125
Outbound: Sending KEXDH_INIT
Protocol.js:125
Received DH Reply
Protocol.js:125
Host accepted by default (no verification)
Protocol.js:125
Host accepted (verified)
Protocol.js:125
CLIENT[sftp]: getConnection: Handling error: Timed out while waiting for handshake
index.js:80
CLIENT[sftp]: getConnection: handled error with reject
index.js:80
CLIENT[sftp]: Global: Ignoring handled error
index.js:80
CLIENT[sftp]: getConnection: finally clause fired
index.js:80
Socket closed
client.js:753
CLIENT[sftp]: getConnection: handling unexpected close event
index.js:80
CLIENT[sftp]: getConnection: handling close event with reject
index.js:80
CLIENT[sftp]: Global: Ignoring handled close event
index.js:80
CLIENT[sftp]: Removing listener from ready event
index.js:80
CLIENT[sftp]: getConnection: Removing temp event listeners
index.js:80
CLIENT[sftp]: getConnection retry catch
index.js:80
CLIENT[sftp]: connect: Error getConnection: Timed out while waiting for handshake
index.js:80```

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 44 (19 by maintainers)

Most upvoted comments

About to push version v7.0.2, which is based on ssh2 1.3.0, that includes the patch to fix the timeout issue.

Sorry, I don’t use docker, so cannot help.

I do know that without exception, every report I have had which involves docker and connection issues has been due to a configuration issue with docker. It is usually related to the network stack and firewalls or MTU settings.

Are you able to connect from within the docker container using openSSH CLI? Have you done basic network diagnosis like pings, traceroutes DNS lookups, disabling firewalls etc?a Do the logs on the remote sftp server provide any clues (if you have access)? Have you tried connecting from the docker container to a different sftp server?

You probably need to seek assistance on a docker specific forum.

This issue is in the ssh2 module. Could you please add a comment to the issue in that repository as the more info available might help find a resolution. See mscdex/ssh2#1040

Note that the 6.x series of ssh2-sftp-client is based on the old ssh2, prior to the rewrite and has significant problems with node v14.x due to network changes in the node stack introduced in v14. These changes were rolled back in v15, but as they did provide significant performance improvements, they are likely to be rolled back in at some future date.

For what it’s worth, I faced the same issue on v7.0.0 and v7.0.1. I am using an M1 mac and have a small suspicion the cpu-features dependency caused the issue. Rolling back to 6.0.1 meant I no longer faced this issue.

Please start by upgrading to v7.0.1 of ssh2-sftp-client.

I would then start by simplifying your config object. Just use

{ host: config.sftpHost, username: config.sftpID, password: config.sftpPW, debug: console.log }

(add back the port setting if your server is not listening on port 22).

See how this goes and if it doesn’t work, post the debug log and we can go from there.