Permalink
Browse files

Big file stream bug fix

  • Loading branch information...
1 parent 1ab6fc0 commit 08d38596c7296b913ca9daf6b53dd28c3a689cbd @bancek bancek committed Nov 26, 2012
Showing with 35 additions and 24 deletions.
  1. +35 −24 lib/jsftp.js
View
@@ -74,6 +74,7 @@ Ftp.queue = function() {
var stream = function stream($, stop) {
next = $;
stream._update();
+ stream.next = $;
};
stream._update = function _update() {
@@ -133,13 +134,7 @@ Ftp.getPasvPort = function(text) {
// a stream that keeps yielding command/response pairs as soon as each pair
// becomes available.
var pairStreamer = S.zip(
- // We ignore FTP marks for now. They don't convey useful
- // information. A more elegant solution should be found in the
- // future.
- S.filter(
- function(x) { return !Ftp.isMark(x.code); },
- self.serverResponse(input)
- ),
+ self.serverResponse(input),
// Stream of FTP commands from the client.
S.append(S.list(null), function(next, stop) { cmd = next; })
);
@@ -370,23 +365,30 @@ Ftp.getPasvPort = function(text) {
var ftpResponse = action[0];
var command = action[1];
var callback = command[1];
- if (callback) {
- if (!ftpResponse) {
- callback(new Error("FTP response not defined"));
- }
- // In FTP every response code above 399 means error in some way.
- // Since the RFC is not respected by many servers, we are going to
- // overgeneralize and consider every value above 399 as an error.
- else if (ftpResponse.code > 399) {
- var err = new Error(ftpResponse.text || "Unknown FTP error.");
- err.code = ftpResponse.code;
- callback(err);
- }
- else {
+ if (Ftp.isMark(ftpResponse.code)) {
+ if (callback.acceptsMarks) {
callback(null, ftpResponse);
}
+ this.cmdQueue.next(['', callback]);
+ } else {
+ if (callback) {
+ if (!ftpResponse) {
+ callback(new Error("FTP response not defined"));
+ }
+ // In FTP every response code above 399 means error in some way.
+ // Since the RFC is not respected by many servers, we are going to
+ // overgeneralize and consider every value above 399 as an error.
+ else if (ftpResponse.code > 399) {
+ var err = new Error(ftpResponse.text || "Unknown FTP error.");
+ err.code = ftpResponse.code;
+ callback(err);
+ }
+ else {
+ callback(null, ftpResponse);
+ }
+ }
+ this.nextCmd();
}
- this.nextCmd();
};
this._initialize = function(callback) {
@@ -553,9 +555,18 @@ Ftp.getPasvPort = function(text) {
if (err) return callback(err);
socket.pause();
- self._enqueueCmd("retr " + path, function(err, res) {
- callback(err, socket);
- });
+
+ var called = false;
+
+ var cmdCallback = function(err, res) {
+ if (!called) {
+ called = true;
+ callback(err, socket);
+ }
+ };
+ cmdCallback.acceptsMarks = true;
+
+ self._enqueueCmd("retr " + path, cmdCallback);
});
};

0 comments on commit 08d3859

Please sign in to comment.