I have searched stackoverflow and google extensivly and not found a solution yet.
Using Typescript, node v16.18.0 and ssh2-sftp-client, the code below can successfully connects to my sftp server (hosted on IIS) which requires a username, password and a private key.
let sftp = new Client();
// sftp.tryKeyboard = true;
let conn = await sftp
.connect({
protocal: 'sftp',
host: '##.##.##.##',
port: 22,
username: 'someUserName',
remotePath: 'somePaht',
password: 'somePassword',
privateKey: key,
// tryKeyboard: true,
})
.then(async() => {
// return;
console.log('You connected!');
})
.catch((err: any) => {
console.log(err, 'catch error');
});
However, using the exact same code but passing in connection parameters for a different sftp server (hosted on Linux) that requires a username and privatekey, but not a password fails to connect.
let sftp = new Client();
// sftp.tryKeyboard = true;
let conn = await sftp
.connect({
protocal: 'sftp',
host: '##.##.##.##',
port: 22,
username: 'gp',
remotePath: 'gp',
//password: 'NA',
privateKey: key,
// tryKeyboard: true,
})
.then(async() => {
// return;
console.log('You connected!');
})
.catch((err: any) => {
console.log(err, 'catch error');
});
and this is the error I get using the above code:
Error: connect: getConnection: All configured authentication methods failed at SftpClient.fmtError (D:\app\node_modules\ssh2-sftp-client\src\index.js:111:22) at SftpClient.connect (D:\app\node_modules\ssh2-sftp-client\src\index.js:249:37) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async getSftpConnection (D:\app\index.ts:67:12) { code: 'ERR_GENERIC_CLIENT', custom: true } catch error
As a test I used the exact same values to connect using the FileZilla ftp client and it connects with no problem. I don’t have admin access to the Linux server so I can’t get additional information about its configuration, but I can confirm that these connection parameter values work in FileZilla. Obviously FileZilla is doing something I am not.
This is the basic configuration in FileZilla:
and the folder it connected to:
How can I troubleshoot this? How can I get additional information about what’s causing the connection to fail?
Thank you.