Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from ajaxorg/fix_onconnect

Fix execution of the custom `onConnect` handler
  • Loading branch information...
commit c3dee03555b0f9712515e181e38554bc48d82e3e 2 parents a754f34 + f65832e
Zef Hemel authored
Showing with 22 additions and 4 deletions.
  1. +7 −3 lib/jsftp.js
  2. +1 −1  package.json
  3. +14 −0 test/jsftp_test.js
View
10 lib/jsftp.js
@@ -49,8 +49,9 @@ var Ftp = module.exports = function(cfg) {
// they will be sent to the server.
this.waitingForEnqueue = [];
- for (var option in cfg)
+ for (var option in cfg) {
if (!this[option]) this[option] = cfg[option];
+ }
this.port = this.port || FTP_PORT;
@@ -85,7 +86,7 @@ Ftp.queue = function() {
}
};
return stream;
-};
+};
// Codes from 100 to 200 are FTP marks
Ftp.isMark = function(code) {
@@ -113,7 +114,6 @@ Ftp.getPasvPort = function(text) {
var self = this;
// Stream of incoming data from the FTP server.
var input = function(next, stop) {
- _socket.on("connect", self.onConnect || function(){});
_socket.on("data", next);
_socket.on("end", stop);
_socket.on("error", stop);
@@ -249,6 +249,10 @@ Ftp.getPasvPort = function(text) {
this.socket.on("connect", function() {
self.connecting = false;
self.emitter.emit("connect", "connect");
+
+ if (self.onConnect)
+ self.onConnect();
+
self._createStreams(self.socket);
if (firstTask) {
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "jsftp",
"id": "jsftp",
- "version": "0.4.7",
+ "version": "0.4.9",
"description": "A sane FTP client implementation for NodeJS",
"keywords": [ "ftp", "protocol", "files", "server", "client", "async" ],
"author": "Sergi Mansilla <sergi.mansilla@gmail.com> (http://sergimansilla.com)",
View
14 test/jsftp_test.js
@@ -364,5 +364,19 @@ describe("jsftp test suite", function() {
});
});
});
+
+ it("test attach event handlers: connect", function(_next) {
+ var clientOnConnect = function() {
+ client.auth(FTPCredentials.user, FTPCredentials.pass, function(err) {
+ assert.ok(!err);
+ client.destroy();
+ _next();
+ });
+ };
+
+ FTPCredentials.onConnect = clientOnConnect;
+
+ var client = new Ftp(FTPCredentials);
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.