Trying to run a sftp
client using nodejs
but getting a wired error. The error is
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
let Client = require('ssh2-sftp-client');
let sftp = new Client();
const process = require('process');
const config = {
host: 'localhost',
port: '1026',
username: 'Nav****',
password: '*******'
}
sftp.connect(config)
const list = ()=>{
sftp.connect(config).then(() => {
return sftp.list('../send_backend');
}).then((data) => {
console.log(data, 'the data info');
}).catch((err) => {
console.log(err, 'catch error');
})
}
console.log("=======================================");
console.log("received data =>" + list());