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

Add Promise versions of methods #285

Open
SeriousMonk opened this issue May 21, 2023 · 0 comments
Open

Add Promise versions of methods #285

SeriousMonk opened this issue May 21, 2023 · 0 comments

Comments

@SeriousMonk
Copy link

Hi,

I am currently trying to use this package to upload an array of files to an ftp server. Currently since the methods only support callbacks, this is impossible if not by writing some horrendous code.

It would be very neat to have promise versions of all methods so that I could write code like this:

const c = new Client();

c.on('ready', async function(){

  for(let f of files){
    try{
      await c.put(`tmp/${req.body.user._id}/${f}`, `images/user/${req.body.user._id}/${f}`);
      fs.unlinkSync(`tmp/${req.body.user._id}/${f}`);
    }catch(e){
      files.splice(files.indexOf(f), 1); //remove file from files array
    }
  }

  c.end();

  return res.status(200).send({success: true, paths: files});
});

c.connect(JSON.parse(process.env.FTP_CONFIG));
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