diff --git a/lib/connection.js b/lib/connection.js index 73bc3a7..bf9feec 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -65,6 +65,7 @@ var FTP = module.exports = function() { this._keepalive = undefined; this._ending = false; this._parser = undefined; + this._offset = undefined; this.options = { host: undefined, port: undefined, @@ -576,10 +577,24 @@ FTP.prototype.get = function(path, zcomp, cb) { sock.destroy(); return cb(makeError(code, 'Compression not supported')); } - sendRetr(); + if(self._offset !== undefined){//Append at offset + self._send('REST ' + self._offset, function(){ + sendRetr(); + self._offset = undefined; + }); + }else + sendRetr(); }, true); - } else - sendRetr(); + } else{ + if(self._offset !== undefined){//Append at offset + self._send('REST ' + self._offset, function(){ + sendRetr(); + self._offset = undefined; + }); + }else + sendRetr(); + } + function sendRetr() { // this callback will be executed multiple times, the first is when server @@ -617,7 +632,14 @@ FTP.prototype.get = function(path, zcomp, cb) { }; FTP.prototype.put = function(input, path, zcomp, cb) { - this._store('STOR ' + path, input, zcomp, cb); + self = this; + if(self._offset !== undefined){ //Append at offset + self._send('REST ' + self._offset, function(){ + this._store('STOR ' + path, input, zcomp, cb); + self._offset = undefined; + }); + }else + this._store('STOR ' + path, input, zcomp, cb); }; FTP.prototype.append = function(input, path, zcomp, cb) { @@ -779,7 +801,8 @@ FTP.prototype.lastMod = function(path, cb) { }; FTP.prototype.restart = function(offset, cb) { - this._send('REST ' + offset, cb); + this._offset = offset; + process.nextTick(cb); };