Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST send before RETR if restart is used. fixes #76 #77

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
34 changes: 29 additions & 5 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -779,7 +801,9 @@ FTP.prototype.lastMod = function(path, cb) {
};

FTP.prototype.restart = function(offset, cb) {
this._send('REST ' + offset, cb);
self = this;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can be removed

self._offset = offset;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be changed to this._offset = offset;

cb();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to keep backwards compatibility by keeping the callback-based signature, we need to at least call the callback on nextTick() instead of calling it immediately.

};


Expand Down