0
我想下載FTP服務器上的遠程位置到我的本地目錄。我一直在使用jsftp模塊(https://github.com/sergi/jsftp),但我遇到了一個問題。NodeJS下載遠程到本地FTP
基本上我試圖遞歸地下載整個遠程位置,包括所有的子文件夾等。我一直試圖弄清楚自己,但迄今沒有運氣。
到目前爲止,我一直想這樣的:
var worker = {
ftp: null,
init: function() {
this.ftp = new JSFtp({
host: "localhost",
port: 21,
user: "username",
pass: "password"
});
this.ftp.auth("username", "password", function (result) {
if (typeof result !== "undefined") {
console.log("Something went wrong");
}
this.handleData();
}.bind(this));
},
handleData: function() {
recursive_get_files(this, "/");
}
};
function recursive_get_files(worker, dir) {
console.log("Getting directory: " + dir);
worker.ftp.ls(dir, function (err, res) {
res.forEach(function (file) {
if (file.type === 1) {
recursive_get_files(worker, dir + "/" + file.name);
} else {
worker.ftp.get(dir + "/" + file.name, "/downloads" + dir + "/" + file.name, function(err) {
if (err) {
console.log("Couldn't download file: " + file.name);
console.log(err);
}
}.bind(file.name));
}
});
});
}
最大的問題,我認爲,是所有這些功能得到越來越之後對方叫幾乎是瞬間,由於客戶端可能是不允許的撥打這麼多東西,它會打破。
我見過一個名爲ftpsync的模塊(https://www.npmjs.com/package/ftpsync)做了一些遠程同步,從本地到遠程,但我需要繞過這條路。
任何人都可以幫助我嗎?我一直在這一天卡住= /。