【发布时间】:2019-11-02 21:09:00
【问题描述】:
尝试使用nodejs 运行sftp 客户端,但出现有线错误。错误是
UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。 (拒绝编号: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());
【问题讨论】: