Skip to content

Commit

Permalink
JSFtp tries to recover the connection if the user was authenticated b…
Browse files Browse the repository at this point in the history
…efore.
  • Loading branch information
sergi committed Aug 10, 2011
1 parent 3e9d488 commit 4ba5525
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions jsftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var Ftp = module.exports = function(cfg) {
* once that one is received
*/
this.push = function(command, callback) {
var self = this;
function send() {
cmd([command, callback]);
socket.write(command + "\r\n");
Expand All @@ -96,8 +97,11 @@ var Ftp = module.exports = function(cfg) {
console.log("Reopening socket...")
socket = this._createSocket(this.port, this.host, function() {
createStreams();
send()
//self.auth(self.currentUser, self.currentPass, send);

if (self.authenticated)
self.auth(self.user, self.pass, function(err, data) {
if (!err) send();
});
});
}
};
Expand Down Expand Up @@ -134,7 +138,6 @@ var Ftp = module.exports = function(cfg) {
};

createStreams();

this.cmd = cmd;
};

Expand Down Expand Up @@ -345,10 +348,13 @@ var Ftp = module.exports = function(cfg) {
if ([230, 331, 332].indexOf(res.code) > -1) {
self.raw.pass(pass, function(err, res) {
if ([230, 202].indexOf(res.code) > -1) {
this.authenticated = true;
this.user = user;
this.pass = pass;
callback(null, res);
}
else if (res.code === 332) {
self.raw.acct("noaccount");
self.raw.acct(""); // ACCT not really supported
}
else {
callback(new Error("Login not accepted"));
Expand Down

0 comments on commit 4ba5525

Please sign in to comment.