Timeout while waiting for handshake or handshake errors
See original GitHub issueHello,
I was working on a script to fetch some files from an sftp server through a SOCKS5 proxy and I noticed some strange behaviour. I managed to use a workaround to make it work, but I saw that people are experiencing this issue so it might be worth investigating more.
I was getting timeouts (Only when using the proxy though) when calling the sftp.connect(ssh_config) function. So I tried using the ssh2 library directly, and I was able to connect without any issue (through the proxy) My workaround was to connect the ssh2 client from outside the ssh2-sftp-client library and do the same calls as the ssh2-sftp-client library afterwards.
const SSHClient = require('ssh2').Client;
const sftpClient = require("ssh2-sftp-client");
const sftp = new sftpClient();
var ssh_config = {
host: process.env.ssh_hostname,
port: process.env.ssh_port,
username: process.env.ssh_username,
privateKey: process.env.ssh_key_secret,
passphrase: process.env.ssh_key_passphrase,
debug: (txt) => { console.log('[ssh]', txt) },
sock: socket
};
function getSftpConnection() {
return new Promise((resolve) => {
var conn = new SSHClient();
sftp.client = conn;
conn.connect(ssh_config);
conn.on('ready', function () {
console.log('sftp connection ready !');
resolve(conn);
});
});
}
await getSftpConnection();
await sftp.getSftpChannel();
await sftp.get(
files_config.remote.inputFilePath,
files_config.local.inputFilePath
); //Works !
The original solution that is failing is :
const sftpClient = require("ssh2-sftp-client");
const sftp = new sftpClient();
var ssh_config = {
host: process.env.ssh_hostname,
port: process.env.ssh_port,
username: process.env.ssh_username,
privateKey: process.env.ssh_key_secret,
passphrase: process.env.ssh_key_passphrase,
debug: (txt) => { console.log('[ssh]', txt) },
sock: socket
};
await sftp.connect(ssh_config); //Fails !
await sftp.get(
files_config.remote.inputFilePath,
files_config.local.inputFilePath
);
I tried to find the cause but didn’t see anything obvious. Maybe it has something to do with one of the event listeners initialized by the library.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
New version of ssh2 just released, so pushing out 7.2.2 now. Will take a little time to get to all the npmjs.com servers.
OK. I have been waiting for a new ssh2 version before pushing out the new ssh2-sftp-client version, but I think I will just have to go ahead and push out a new one now and do another one later if necessary once a new ssh2 is released. Bit of a pain as I know there are a couple of issues people are encountering which are fixed in ssh2 master.
I’ll push a new version out on Monday.