Skip to content

Commit e0842da

Browse files
committed
add proxy support
1 parent 7cacec7 commit e0842da

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ var Ftp = new JSFtp({
2626
});
2727
```
2828

29+
Through a proxy:
30+
31+
```javascript
32+
var Ftp = new JSFtp({
33+
host: proxy.host,
34+
port: ftp.port,
35+
user: `${ftp.user}@${ftp.host} ${proxy.user}`,
36+
pass: ftp.pass,
37+
cwd: '/82844',
38+
root: '/82844',
39+
debugMode: true,
40+
acct: proxy.pass
41+
})
42+
```
43+
44+
2945
jsftp gives you access to all the raw commands of the FTP protocol in form of
3046
methods in the `Ftp` object. It also provides several convenience methods for
3147
actions that require complex chains of commands (e.g. uploading and retrieving

lib/jsftp.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var Ftp = module.exports = function(cfg) {
7676
this.port = cfg.port || FTP_PORT;
7777
this.user = cfg.user || 'anonymous';
7878
this.pass = cfg.pass || '@anonymous';
79+
this.acct = cfg.acct || ''
7980
// True if the server doesn't support the `stat` command. Since listing a
8081
// directory or retrieving file properties is quite a common operation, it is
8182
// more efficient to avoid the round-trip to the server.
@@ -234,7 +235,7 @@ Ftp.prototype.runCommand = function(action, callback) {
234235

235236
var self = this;
236237
this.getFeatures(function() {
237-
self.auth(self.user, self.pass, function() {
238+
self.auth(self.user, self.pass, self.acct, function() {
238239
self.commandQueue.push(cmd);
239240
self.nextCmd();
240241
});
@@ -316,9 +317,8 @@ Ftp.prototype.getFeatures = function(callback) {
316317
* @param {String} pass Password
317318
* @param {Function} callback Follow-up function.
318319
*/
319-
Ftp.prototype.auth = function(user, pass, callback) {
320+
Ftp.prototype.auth = function(user, pass, acct, callback) {
320321
var self = this;
321-
322322
if (this.authenticating === true) {
323323
return callback(new Error('This client is already authenticating'));
324324
}
@@ -329,6 +329,9 @@ Ftp.prototype.auth = function(user, pass, callback) {
329329
if (!pass) {
330330
pass = '@anonymous';
331331
}
332+
if (!acct) {
333+
acct = ''
334+
}
332335

333336
this.authenticating = true;
334337
self.raw('user', user, function(err, res) {
@@ -338,19 +341,23 @@ Ftp.prototype.auth = function(user, pass, callback) {
338341
return;
339342
}
340343
self.raw('pass', pass, function(err, res) {
341-
self.authenticating = false;
342-
343344
if (err) {
345+
self.authenticating = false;
344346
callback(err);
345347
} else if ([230, 202].indexOf(res.code) > -1) {
348+
self.authenticating = false;
346349
self.authenticated = true;
347350
self.user = user;
348351
self.pass = pass;
349352
self.raw('type', 'I', function() {
350353
callback(undefined, res);
351354
});
352355
} else if (res.code === 332) {
353-
self.raw('acct', ''); // ACCT not really supported
356+
self.raw('acct', acct, function (err, res) {
357+
self.authenticating = false;
358+
self.authenticated = true;
359+
callback(undefined, res)
360+
}); // ACCT not really supported
354361
}
355362
});
356363
});

test/jsftp_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('jsftp test suite', function() {
7878
ftp.auth(
7979
options.user,
8080
options.pass + '_invalid',
81+
null,
8182
function(err, data) {
8283
assert.equal(err.code, 530);
8384
assert.equal(data, null);
@@ -554,7 +555,7 @@ describe('jsftp test suite', function() {
554555

555556
it('test attach event handlers: connect', function(_next) {
556557
var clientOnConnect = function() {
557-
client.auth(options.user, options.pass, next);
558+
client.auth(options.user, options.pass, null, next);
558559
};
559560

560561
var next = function(err) {

0 commit comments

Comments
 (0)