Skip to content
Browse files

Fixed bug in which pasv requests would ignore the host if it is not t…

…he original one
  • Loading branch information...
1 parent 3349412 commit fca717c235298f54c7cd057a1ebb4b922cec4b40 @sergi committed Dec 30, 2012
Showing with 18 additions and 8 deletions.
  1. +4 −0 README.md
  2. +13 −7 lib/jsftp.js
  3. +1 −1 package.json
View
4 README.md
@@ -208,6 +208,10 @@ used is written in python.
Changelog
---------
+**0.5.6**
+- Fixed bug in which passive requests would ignore the host if it was not the
+ same as the original host.
+
**0.5.5**
- Solved issues and hangs when uploading big files
View
20 lib/jsftp.js
@@ -13,7 +13,7 @@ var S = require("streamer");
var slice = Array.prototype.slice;
var FTP_PORT = 21;
-var RE_PASV = /[-\d]+,[-\d]+,[-\d]+,[-\d]+,([-\d]+),([-\d]+)/;
+var RE_PASV = /([-\d]+,[-\d]+,[-\d]+,[-\d]+),([-\d]+),([-\d]+)/;
var RE_RES = /^(\d\d\d)\s(.*)/;
var RE_MULTI = /^(\d\d\d)-/;
var RE_NL_END = /\r\n$/;
@@ -107,7 +107,11 @@ Ftp.getPasvPort = function(text) {
var match = RE_PASV.exec(text);
if (!match) return false;
- return (parseInt(match[1], 10) & 255) * 256 + (parseInt(match[2], 10) & 255);
+ // Array containing the passive host and the port number
+ var address = [match[1].replace(/,/g, "."),
+ (parseInt(match[2], 10) & 255) * 256 + (parseInt(match[3], 10) & 255)];
+
+ return address
};
(function() {
@@ -411,7 +415,7 @@ Ftp.getPasvPort = function(text) {
* @returns {String} Sanitized command
*/
this._sanitize = function(cmd) {
- if (!cmd) return;
+ if (!cmd) return "";
var _cmd = cmd.slice(0, 5);
if (_cmd === "pass ")
@@ -625,11 +629,13 @@ Ftp.getPasvPort = function(text) {
return callback(new Error("Unknown error when trying to get into PASV mode"));
}
- var port = Ftp.getPasvPort(res.text);
- if (port === false)
- return callback(new Error("PASV: Bad port"));
+ var pasvRes = Ftp.getPasvPort(res.text);
+ if (pasvRes === false)
+ return callback(new Error("PASV: Bad host/port combination"));
- var socket = Net.createConnection(port, self.host);
+ var host = pasvRes[0];
+ var port = pasvRes[1];
+ var socket = Net.createConnection(port, host);
socket.setTimeout(self.timeout || TIMEOUT);
callback(null, socket);
};
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "jsftp",
"id": "jsftp",
- "version": "0.5.5",
+ "version": "0.5.6",
"description": "A sane FTP client implementation for NodeJS",
"keywords": [ "ftp", "protocol", "files", "server", "client", "async" ],
"author": "Sergi Mansilla <sergi.mansilla@gmail.com> (http://sergimansilla.com)",

0 comments on commit fca717c

Please sign in to comment.
Something went wrong with that request. Please try again.