diff --git a/lib/client.js b/lib/client.js index ca999b7..bb6df8c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -6,7 +6,7 @@ var fs = require('fs'), glob = require('glob'), async = require('async'), Client, - MAX_CONNECTIONS = 10, + MAX_CONNECTIONS = 100, logging = 'basic', loggingLevels = ['none', 'basic', 'debug'], log = function (msg, lvl) { @@ -58,6 +58,22 @@ Client.prototype.connect = function (callback) { this.ftp.connect(this.config || {}); }; +Client.prototype.rename = function (from, to) { + var ftp = this.ftp + return new Promise(function(resolve, reject) { + ftp.rename(from, to, (err) => { + if (err) { + reject(err) + } + resolve(`file ${from} moved`) + }) + }); +}; + +Client.prototype.close = function () { + this.ftp.end() +} + Client.prototype.upload = function (patterns, dest, options, uploadCallback) { options = _.defaults(options || {}, this.options); @@ -272,12 +288,23 @@ Client.prototype.download = function (source, dest, options, downloadCallback) { var queue = async.queue(function (task, callback) { log('Queue worker started for ' + task.src, 'debug'); ftp.list(task.src, function (err, list) { - if (err || typeof list === 'undefined' || typeof list[0] === 'undefined') { - throw new Error('The source directory on the server ' + task.src + ' does not exist.'); - } + + console.log('TASK =>', task); + console.log('LIST =>', list); + console.log('ERR ? =>', err); + + + if (err && err !== undefined) { + throw new Error('The source directory on the server ' + task.src + ' does not exist.'); + } + + // Original + // if (err || typeof list === 'undefined' || typeof list[0] === 'undefined') { + // throw new Error('The source directory on the server ' + task.src + ' does not exist.'); + // } if (list && list.length > 1) { - _.each(list.splice(1, list.length - 1), function (file) { + _.each(list.splice(0, list.length), function (file) { if (file.name !== '.' && file.name !== '..') { var filename = task.src + '/' + file.name; if (file.type === 'd') { @@ -292,6 +319,8 @@ Client.prototype.download = function (source, dest, options, downloadCallback) { } } }); + } else { + console.log('DEST FOLDER EMPTY') } callback(); @@ -498,4 +527,4 @@ Client.prototype._clean = function (files, baseDir) { return null; } })); -} \ No newline at end of file +}