ssh2-sftp-client
,即使在事件发生后,程序也不会终止并挂起
end, close
在ReadableStream和事件上触发
finish and close
在可写流上触发。下面是程序及其输出。也没有错误,如何调试?发生了什么事?任何帮助都将不胜感激
const Promise = require("bluebird");
const fs = require("fs");
const Client = require("ssh2-sftp-client");
const util = require("util");
const sftp = new Client();
const path = require("path");
const openpgp = require("openpgp"); // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.initWorker({
path: "openpgp.worker.js"
}); // set the relative web worker path
const config = {
host: 'xxxx',
port: '1111',
username: 'xxxx',
password: 'xxxx'
};
function getFileFromSFTP() {
console.log("Program Execution started");
/* get files from SFTP */
const remotePath = "remoteFile";
const localPath = "localFile"
sftp.connect(config).then(() => {
sftp.get(remotePath, true, null).then((data) => {
data.on('error', (e) => {
console.log(e);
});
data.on('end', () => {
console.log("rs end");
});
data.on('close', () => {
console.log("rs closed");
});
data.pipe(fs.createWriteStream(localPath).on('error', (e) => {
console.log(e);
}).on('finish', () => {
console.log("ws finish");
}).on('close', () => {
console.log("ws close");
}));
});
});
}
function init() {
getFileFromSFTP();
}
init();
输出
> node index.js
Program Execution started
rs end
ws finish
ws close
rs closed