Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Throw Error not string; Fix streamer dependency version; Allow leadin…

…g leading space; Fix Auth erroring; Fix test #2
  • Loading branch information...
commit f16e30dd60eaa407719950ab4c87af90d28513e5 1 parent 35b525c
@CrabDude CrabDude authored
Showing with 21 additions and 12 deletions.
  1. +11 −5 jsftp.js
  2. +7 −4 jsftp_test.js
  3. +2 −2 lib/ftpParser.js
  4. +1 −1  package.json
View
16 jsftp.js
@@ -342,13 +342,19 @@ var Ftp = module.exports = function(cfg) {
var ftpResponse = action[0];
var command = action[1];
var callback = command[1];
+ var err;
if (callback) {
// In FTP every response code above 399 means error in some way.
// Since the RFC is not respected by many servers, we are goiong to
// overgeneralize and consider every value above 399 as an error.
- var hasFailed = ftpResponse && ftpResponse.code > 399;
- callback(hasFailed && (ftpResponse.text || "Unknown FTP error."), ftpResponse);
+ if (ftpResponse && ftpResponse.code > 399) {
+ err = new Error(ftpResponse.text || "Unknown FTP error.")
+ err.code = ftpResponse.code;
+ callback(err);
+ } else {
+ callback(null, ftpResponse);
+ }
}
this.nextCmd();
};
@@ -453,11 +459,11 @@ var Ftp = module.exports = function(cfg) {
this.authenticating = true;
//this._initialize(function() {
self.raw.user(user, function(err, res) {
- if ([230, 331, 332].indexOf(res.code) > -1) {
+ if (!err && [230, 331, 332].indexOf(res.code) > -1) {
self.raw.pass(pass, function(err, res) {
self.authenticating = false;
- if ([230, 202].indexOf(res.code) > -1) {
+ if (!err && [230, 202].indexOf(res.code) > -1) {
self.authenticated = true;
self.user = user;
self.pass = pass;
@@ -468,7 +474,7 @@ var Ftp = module.exports = function(cfg) {
});
notifyAll(null, res);
}
- else if (res.code === 332) {
+ else if (!err && res.code === 332) {
self.raw.acct(""); // ACCT not really supported
}
else {
View
11 jsftp_test.js
@@ -138,10 +138,13 @@ module.exports = {
});
ftp.raw.cwd("/unexistentDir/", function(err, res) {
- assert.ok(err);
-
- code = parseInt(res.code, 10);
- assert.ok(code === 550, "A (wrong) CWD command was successful. It should have failed");
+ if (err)
+ assert.ok(err);
+ else {
+ code = parseInt(res.code, 10);
+ assert.ok(code === 550, "A (wrong) CWD command was successful. It should have failed");
+ }
+
next();
});
});
View
4 lib/ftpParser.js
@@ -44,7 +44,7 @@ var RE_UnixEntry = new RegExp(
// year (for non-recent standard format)
// or time (for numeric or recent standard format)
- + "(\\d+(?::\\d+)?)\\s+"
+ + "(\\d+(?::\\d+)?)\\s?"
//+ "(\\S*)(\\s*.*)"
+ "(.*)"
@@ -57,7 +57,7 @@ var RE_UnixEntry = new RegExp(
var RE_DOSEntry = new RegExp(
"(\\S+)\\s+(\\S+)\\s+"
+ "(<DIR>)?\\s*"
- + "([0-9]+)?\\s+"
+ + "([0-9]+)?\\s?"
+ "(\\S.*)"
);
View
2  package.json
@@ -14,7 +14,7 @@
"web": "https://github.com/sergi/jsftp/issues"
},
"dependencies": {
- "streamer": "=0.0.4"
+ "streamer": "0.2.x"
},
"devDependencies": {
"asyncjs": ">=0.0.5"
Please sign in to comment.
Something went wrong with that request. Please try again.