node-ftps icon indicating copy to clipboard operation
node-ftps copied to clipboard

async/await

Open nine-2-five opened this issue 7 years ago • 2 comments

Is this library compatible with async/await?

I tried this:

var result = await ftps.mirror({
        remoteDir: remote_path, // + '/.',
        localDir: commit_dir + '/' + commit_diffs.commit + '/.',
        //parallel: true,
        upload: true,
        //filter: '/.**/',
    }).exec()

and got this: Error: Callback is missing to exec() function.

nine-2-five avatar Apr 20 '17 20:04 nine-2-five

async/await works with functions that returns a Promise. So to make this work, you gotta make ftps.mirror().exec() return a promise.

cjnqt avatar May 16 '17 09:05 cjnqt

async/await works with functions that returns a Promise. So to make this work, you gotta make ftps.mirror().exec() return a promise.

Just in case people wants the gist of making this module works with async/await here's what I did. Sorry for necroposting.

const mirrorFTP = new Promise((resolve, reject) => {
  return ftps.mirror({
    remoteDir: remote_path, // + '/.',
    localDir: commit_dir + '/' + commit_diffs.commit + '/.',
    //parallel: true,
    upload: true,
    //filter: '/.**/',
  }).exec((err, res) => {
    if (res.error) { reject(`❌ FTP sync error: ${res.error}`) }
    resolve(`✔️ FTP Mirroring done`)
  })
})

try {
  const result = await mirrorFTP
  console.log(result)
} catch (e) {
  console.error(e)
}

SkullMasher avatar Mar 21 '23 20:03 SkullMasher