Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to multiple get files [solution] #320

Open
bombkiml opened this issue Jan 18, 2024 · 0 comments
Open

How to multiple get files [solution] #320

bombkiml opened this issue Jan 18, 2024 · 0 comments

Comments

@bombkiml
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant