How to multiple get files [solution]
bombkiml opened this issue · 0 comments
bombkiml commented
const jsftp = require("jsftp");
var async = require("async");
const dir = "./srcFolders";
const save_to = "localFolder";
const Ftp = new jsftp({
host: "192.168.xx.xxx",
port: "",
user: "user_access",
pass: "secret_password",
});
gatherFiles(dir) {
return new Promise(function (resolve, reject) {
Ftp.ls(dir + "/*", function (err, res) {
if (err) reject(err);
var files = [];
res.forEach(function (file) {
files.push(file.name);
});
resolve(files);
});
});
};
this.gatherFiles(dir).then((files) => {
async.mapLimit(files, 1, (file, callback) => {
// multiple save delay (needed)
setTimeout(() => {
// Save to local
Ftp.get(dir+ file, save_to.concat("/" + file), (err) => {
if (err) {
console.error("There was an error retrieving the file.", err);
callback(err);
} else {
console.log(" - Saved>>", file);
callback();
}
});
}, 1000);
}, (err, res) => {
if (err) {
console.log(err);
console.log("Save file error is Break!!!");
}
console.log("Save completed");
}
);
});
Enjoy