Friday, 26 May 2017

new Promise() callback function not working

I'm using this code for download a zip file from a remote server. After getting it i want to unzip it.

I wrote this:

var PromiseFtp = require('promise-ftp');

  var ftp = new PromiseFtp();

  ftp.connect({
          host: 'server',
          user: 'user',
          password: 'pass'
      })
      .then(function(serverMessage) {
          return ftp.list('/folder/');
      }).then(function(list) {
          return ftp.get('/folder/' + list[0].name);
      }).then(function(stream) {
          return new Promise(function(resolve, reject) {
              stream.once('close', resolve);
              stream.once('error', reject);
              stream.pipe(fs.createWriteStream('foo.local-copy.zip'));
              fs.createReadStream('foo.local-copy.zip').pipe(unzip.Extract({
                  path: '.'
              }));
          });
      }).then(function() {
          return ftp.end();
      });

This part of program .then(function(stream) is not triggered and i don't know why.

what's wrong?

thanks in advance.



via OiRc

No comments:

Post a Comment