Skip to content

Commit fa5ac04

Browse files
committed
Add proxy support
1 parent 7cacec7 commit fa5ac04

File tree

5 files changed

+84
-8
lines changed

5 files changed

+84
-8
lines changed

Diff for: README.md

+16
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

Diff for: lib/jsftp.js

+13-6
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
});

Diff for: npm-debug.log

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/home/clement/.nvm/versions/node/v6.9.4/bin/node',
3+
1 verbose cli '/home/clement/.nvm/versions/node/v6.9.4/bin/npm',
4+
1 verbose cli 'run',
5+
1 verbose cli 'test',
6+
1 verbose cli '-',
7+
1 verbose cli '-g',
8+
1 verbose cli 'test invalid password' ]
9+
2 info using [email protected]
10+
3 info using [email protected]
11+
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
12+
5 info lifecycle [email protected]~pretest: [email protected]
13+
6 silly lifecycle [email protected]~pretest: no script for pretest, continuing
14+
7 info lifecycle [email protected]~test: [email protected]
15+
8 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true
16+
9 verbose lifecycle [email protected]~test: PATH: /home/clement/.nvm/versions/node/v6.9.4/lib/node_modules/npm/bin/node-gyp-bin:/home/clement/dev/jsftp/node_modules/.bin:/home/clement/.rvm/gems/ruby-1.8.7-head/bin:/home/clement/.rvm/gems/ruby-1.8.7-head@global/bin:/home/clement/.rvm/rubies/ruby-1.8.7-head/bin:/home/clement/bin:/home/clement/.local/bin:/home/clement/.nvm/versions/node/v6.9.4/bin:/home/clement/bin:/home/clement/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/clement/.rvm/bin:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/clement/.rvm/bin:/home/clement/Android/Sdk/tools:/home/clement/Android/Sdk/platform-tools:/home/clement/.rvm/bin
17+
10 verbose lifecycle [email protected]~test: CWD: /home/clement/dev/jsftp
18+
11 silly lifecycle [email protected]~test: Args: [ '-c', 'mocha -R spec -t 5000 "-" "test invalid password"' ]
19+
12 silly lifecycle [email protected]~test: Returned: code: 1 signal: null
20+
13 info lifecycle [email protected]~test: Failed to exec test script
21+
14 verbose stack Error: [email protected] test: `mocha -R spec -t 5000 "-" "test invalid password"`
22+
14 verbose stack Exit status 1
23+
14 verbose stack at EventEmitter.<anonymous> (/home/clement/.nvm/versions/node/v6.9.4/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
24+
14 verbose stack at emitTwo (events.js:106:13)
25+
14 verbose stack at EventEmitter.emit (events.js:191:7)
26+
14 verbose stack at ChildProcess.<anonymous> (/home/clement/.nvm/versions/node/v6.9.4/lib/node_modules/npm/lib/utils/spawn.js:40:14)
27+
14 verbose stack at emitTwo (events.js:106:13)
28+
14 verbose stack at ChildProcess.emit (events.js:191:7)
29+
14 verbose stack at maybeClose (internal/child_process.js:877:16)
30+
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
31+
15 verbose pkgid [email protected]
32+
16 verbose cwd /home/clement/dev/jsftp
33+
17 error Linux 4.4.0-75-generic
34+
18 error argv "/home/clement/.nvm/versions/node/v6.9.4/bin/node" "/home/clement/.nvm/versions/node/v6.9.4/bin/npm" "run" "test" "-" "-g" "test invalid password"
35+
19 error node v6.9.4
36+
20 error npm v3.10.10
37+
21 error code ELIFECYCLE
38+
22 error [email protected] test: `mocha -R spec -t 5000 "-" "test invalid password"`
39+
22 error Exit status 1
40+
23 error Failed at the [email protected] test script 'mocha -R spec -t 5000 "-" "test invalid password"'.
41+
23 error Make sure you have the latest version of node.js and npm installed.
42+
23 error If you do, this is most likely a problem with the jsftp package,
43+
23 error not with npm itself.
44+
23 error Tell the author that this fails on your system:
45+
23 error mocha -R spec -t 5000 "-" "test invalid password"
46+
23 error You can get information on how to open an issue for this project with:
47+
23 error npm bugs jsftp
48+
23 error Or if that isn't available, you can get their info via:
49+
23 error npm owner ls jsftp
50+
23 error There is likely additional logging output above.
51+
24 verbose exit [ 1, true ]

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"mocha": "^3.2.0",
3737
"mocha-istanbul": "0.2.0",
3838
"rimraf": "^2.2.8",
39-
"sinon": "^1.17.7"
39+
"sinon": "^1.17.7",
40+
"socksv5": "0.0.6"
4041
},
4142
"main": "lib/jsftp.js",
4243
"engines": {

Diff for: test/jsftp_test.js

+2-1
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)