Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check if server sends new cwd in CWD reply

  • Loading branch information...
commit f9983c8f7047ae22170e0338cf75b7d962cfebd9 1 parent 29795e1
@mscdex authored
Showing with 13 additions and 5 deletions.
  1. +1 −1  README.md
  2. +12 −4 lib/ftp.js
View
2  README.md
@@ -152,7 +152,7 @@ Methods
* **delete**(< _string_ >path, < _function_ >callback) - _(void)_ - Deletes a file, `path`, on the server. `callback` has 1 parameter: < _Error_ >err.
-* **cwd**(< _string_ >path, < _function_ >callback) - _(void)_ - Changes the current working directory to `path`. `callback` has 2 parameters: < _Error_ >err, < _string_ >currentDir.
+* **cwd**(< _string_ >path, < _function_ >callback) - _(void)_ - Changes the current working directory to `path`. `callback` has 2 parameters: < _Error_ >err, < _string_ >currentDir. Note: `currentDir` is only given if the server replies with the path in the response text.
* **abort**(< _function_ >callback) - _(void)_ - Aborts the current data transfer (e.g. from get(), put(), or list()). `callback` has 1 parameter: < _Error_ >err.
View
16 lib/ftp.js
@@ -326,7 +326,8 @@ FTP.prototype.cwd = function(path, cb) {
this._send('CWD ' + path, function(err, text, code) {
if (err)
return cb(err);
- cb(undefined, /"(.+)"(?: |$)/.exec(text)[1]);
+ var m = /"(.+)"(?: |$)/.exec(text);
+ cb(undefined, m ? m[1] : undefined);
});
};
@@ -579,9 +580,16 @@ FTP.prototype.append = function(input, path, zcomp, cb) {
FTP.prototype.pwd = function(cb) { // PWD is optional
var self = this;
this._send('PWD', function(err, text, code) {
- if (code == 502)
- return self.cwd('.', cb, true);
- else if (err)
+ if (code == 502) {
+ return self.cwd('.', function(cwderr, cwd) {
+ if (cwderr)
+ return cb(cwderr);
+ if (cwd === undefined)
+ cb(err);
+ else
+ cb(undefined, cwd);
+ }, true);
+ } else if (err)
return cb(err);
cb(undefined, /^"(.+)"(?: |$)/.exec(text)[1]);
});
Please sign in to comment.
Something went wrong with that request. Please try again.