1

I can connect to the remote SFTP server fine through FileZilla, and have determined the remote server uses the following:

  • diffie-hellman-group1-sha1
  • ecdh-sha2-nistp521
  • aes256-ctr
  • ecdsa-sha2-nistp521

I am trying to connect to it using the NPM package ssh2-sftp-client here.

My code is the following:

let Client = require('ssh2-sftp-client');

async function main() {
 try {
    let sftp = new Client();

    sftp.on('error', (err) => {
        sftp.errorHandled = true;
        console.log('custom error handler', err);
    });

    await sftp.connect({
        host: 'server',
        username: 'username',
        password: 'password',
        port: 60022,
        readyTimeout: 20000,
        debug: console.log,
        algorithms: {
            kex: [
              "diffie-hellman-group1-sha1",
              "ecdh-sha2-nistp521"
            ],
            cipher: [
              "aes256-ctr"
            ],
            serverHostKey: [
              "ssh-rsa",
              "ecdsa-sha2-nistp521"
            ],
            hmac: [
              "hmac-sha2-256"
            ]
        }
    });

    let result = await sftp.list(`/`);

    console.log(result);

    await sftp.end();
   } catch (err) {
    console.log('catch', err)
  }
}

 main();

process.on('uncaughtException', (err) => {
console.log('uncaught', err);
process.exit(0);
 })

I keep getting the following error:

Handled Error: Timed out while waiting for handshake undefined

I have also tried with the NPM package: SSH2 here

No matter what kind of configuration I try, it always errors out. Does any one have any ideas?

Jim Dover
  • 593
  • 2
  • 12
  • 30
  • 1
    Have you tried increasing the `readyTimeout`? OpenSSL does some (forced) validation of diffie-hellman key exchange values which could take awhile. Connecting to a server using the curve25519 key exchange however should avoid those validations. – mscdex Aug 08 '21 at 15:03
  • Did you find any fix for this? – Amit Anand Jan 24 '22 at 05:59
  • No, I did not unfortunately. I ended up using an NPM package called yocto-sftp which worked fine. – Jim Dover Mar 16 '22 at 18:10

0 Answers0