diff --git a/README.md b/README.md index a2ee9c9..3d2a694 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,22 @@ var Ftp = new JSFtp({ }); ``` +Through a proxy: + +```javascript +var Ftp = new JSFtp({ + host: proxy.host, + port: ftp.port, + user: `${ftp.user}@${ftp.host} ${proxy.user}`, + pass: ftp.pass, + cwd: '/82844', + root: '/82844', + debugMode: true, + acct: proxy.pass +}) +``` + + jsftp gives you access to all the raw commands of the FTP protocol in form of methods in the `Ftp` object. It also provides several convenience methods for actions that require complex chains of commands (e.g. uploading and retrieving diff --git a/lib/jsftp.js b/lib/jsftp.js index d48c2de..92f3b42 100644 --- a/lib/jsftp.js +++ b/lib/jsftp.js @@ -76,6 +76,7 @@ var Ftp = module.exports = function(cfg) { this.port = cfg.port || FTP_PORT; this.user = cfg.user || 'anonymous'; this.pass = cfg.pass || '@anonymous'; + this.acct = cfg.acct || '' // True if the server doesn't support the `stat` command. Since listing a // directory or retrieving file properties is quite a common operation, it is // more efficient to avoid the round-trip to the server. @@ -234,7 +235,7 @@ Ftp.prototype.runCommand = function(action, callback) { var self = this; this.getFeatures(function() { - self.auth(self.user, self.pass, function() { + self.auth(self.user, self.pass, self.acct, function() { self.commandQueue.push(cmd); self.nextCmd(); }); @@ -316,9 +317,8 @@ Ftp.prototype.getFeatures = function(callback) { * @param {String} pass Password * @param {Function} callback Follow-up function. */ -Ftp.prototype.auth = function(user, pass, callback) { +Ftp.prototype.auth = function(user, pass, acct, callback) { var self = this; - if (this.authenticating === true) { return callback(new Error('This client is already authenticating')); } @@ -329,6 +329,9 @@ Ftp.prototype.auth = function(user, pass, callback) { if (!pass) { pass = '@anonymous'; } + if (!acct) { + acct = '' + } this.authenticating = true; self.raw('user', user, function(err, res) { @@ -338,11 +341,11 @@ Ftp.prototype.auth = function(user, pass, callback) { return; } self.raw('pass', pass, function(err, res) { - self.authenticating = false; - if (err) { + self.authenticating = false; callback(err); } else if ([230, 202].indexOf(res.code) > -1) { + self.authenticating = false; self.authenticated = true; self.user = user; self.pass = pass; @@ -350,7 +353,11 @@ Ftp.prototype.auth = function(user, pass, callback) { callback(undefined, res); }); } else if (res.code === 332) { - self.raw('acct', ''); // ACCT not really supported + self.raw('acct', acct, function (err, res) { + self.authenticating = false; + self.authenticated = true; + callback(undefined, res) + }); // ACCT not really supported } }); }); diff --git a/package.json b/package.json index 6501605..108e7f6 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "mocha": "^3.2.0", "mocha-istanbul": "0.2.0", "rimraf": "^2.2.8", - "sinon": "^1.17.7" + "sinon": "^1.17.7", + "socksv5": "0.0.6" }, "main": "lib/jsftp.js", "engines": { diff --git a/test/jsftp_test.js b/test/jsftp_test.js index c6da2dc..434299c 100755 --- a/test/jsftp_test.js +++ b/test/jsftp_test.js @@ -78,6 +78,7 @@ describe('jsftp test suite', function() { ftp.auth( options.user, options.pass + '_invalid', + null, function(err, data) { assert.equal(err.code, 530); assert.equal(data, null); @@ -554,7 +555,7 @@ describe('jsftp test suite', function() { it('test attach event handlers: connect', function(_next) { var clientOnConnect = function() { - client.auth(options.user, options.pass, next); + client.auth(options.user, options.pass, null, next); }; var next = function(err) {