I'm using this code for download a zip from a server and then unzip it in my local directory.
the get function works but when is time to unzip and write in my local system the code doesn't work.
In specific .then() function is never triggered.
this is my code:
var connectionProperties = {
host: "server",
user: "user",
password: "password"
};
var Client = require('ftp');
var fs = require('fs');
var unzip = require('unzip');
var c = new Client();
var p = new Promise(function(resolve, reject) {
c.on('ready', function() {
c.list('/directory/', function(err, list) {
if (err) throw err;
if (list[2].name == 'TX') {
c.get('/directory/' + list[0].name, function(err, stream) {
if (err) throw err;
return stream;
});
}
});
c.end();
});
}).then(function(stream) {
stream.pipe(fs.createWriteStream('foo.local-copy.zip'));
fs.createReadStream('foo.local-copy.zip').pipe(unzip.Extract({
path: '.'
}));
});
c.connect(connectionProperties);
what's wrong with this code?
thanks in advance.
via OiRc
No comments:
Post a Comment