Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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') {
Expand All @@ -292,6 +319,8 @@ Client.prototype.download = function (source, dest, options, downloadCallback) {
}
}
});
} else {
console.log('DEST FOLDER EMPTY')
}

callback();
Expand Down Expand Up @@ -498,4 +527,4 @@ Client.prototype._clean = function (files, baseDir) {
return null;
}
}));
}
}