Node.js 用蓝鸟预测节点SSH2 SFTP
我使用的是我的FTP要求。 我尝试了下面提到的代码:Node.js 用蓝鸟预测节点SSH2 SFTP,node.js,bluebird,Node.js,Bluebird,我使用的是我的FTP要求。 我尝试了下面提到的代码: 'use strict'; global.Promise = require("bluebird"); global._ = require('lodash'); var Client = Promise.promisifyAll(require('ssh2').Client); Promise.promisifyAll(Client.prototype); var clientObject, conn; function getCl
'use strict';
global.Promise = require("bluebird");
global._ = require('lodash');
var Client = Promise.promisifyAll(require('ssh2').Client);
Promise.promisifyAll(Client.prototype);
var clientObject, conn;
function getClient() {
return new Promise((resolve, reject) => {
if (clientObject) resolve(clientObject);
let authObj = {
host: 'abc',
port: 22,
username: 'name',
password: 'password'
};
conn = new Client();
conn.connect(authObj);
conn.on('ready', () => {
conn.sftp((err, sftp) => {
if (err) reject(err);
clientObject = sftp;
resolve(clientObject)
});
});
conn.on('error', (err) => { reject(err) });
});
}
function getList(){
getClient().then((cObj)=>{
cObj.readdir('.').then((list)=>{
_.each(list, (file)=>{console.log(file.filename)});
});
});
}
getList();
上面给出的错误如下:
Unhandled rejection TypeError: cObj.readdir(...).then is not a function
.
.
.
/home/nk/test/node_modules/ssh2-streams/lib/sftp.js:1583
cb(undefined, entries);
^
TypeError: cb is not a function
at /home/nk/test/node_modules/ssh2-streams/lib/sftp.js:1583:13
从以上误差;它看起来像是指向这条线
有可能实现吗?我已经创建了一个npm包来满足同样的需求。我已承诺SSH2和SFTP项目。希望它能有所帮助试试
readdirAsync
?当promisifyAll
时,bluebird将为每个方法添加一个Async
版本。它给了我一个错误:未处理的拒绝类型错误:cObj.readdirAsync不是一个函数
@TuanAnhTran<代码>控制台.log(cObj.readdir)代码>给我[函数]
;而console.log(cObj.readdirAsync)代码>给我未定义的