Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions lib/jsftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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'));
}
Expand All @@ -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) {
Expand All @@ -338,19 +341,23 @@ 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;
self.raw('type', 'I', function() {
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
}
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/jsftp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down