Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #3 from ajaxorg/fix_onconnect

Fix execution of the custom `onConnect` handler
  • Loading branch information...
commit c3dee03555b0f9712515e181e38554bc48d82e3e 2 parents a754f34 + f65832e
authored November 15, 2012
10  lib/jsftp.js
@@ -49,8 +49,9 @@ var Ftp = module.exports = function(cfg) {
49 49
     // they will be sent to the server.
50 50
     this.waitingForEnqueue = [];
51 51
 
52  
-    for (var option in cfg)
  52
+    for (var option in cfg) {
53 53
         if (!this[option]) this[option] = cfg[option];
  54
+    }
54 55
 
55 56
     this.port = this.port || FTP_PORT;
56 57
 
@@ -85,7 +86,7 @@ Ftp.queue = function() {
85 86
         }
86 87
     };
87 88
     return stream;
88  
-};  
  89
+};
89 90
 
90 91
 // Codes from 100 to 200 are FTP marks
91 92
 Ftp.isMark = function(code) {
@@ -113,7 +114,6 @@ Ftp.getPasvPort = function(text) {
113 114
         var self = this;
114 115
         // Stream of incoming data from the FTP server.
115 116
         var input = function(next, stop) {
116  
-            _socket.on("connect", self.onConnect || function(){});
117 117
             _socket.on("data", next);
118 118
             _socket.on("end", stop);
119 119
             _socket.on("error", stop);
@@ -249,6 +249,10 @@ Ftp.getPasvPort = function(text) {
249 249
         this.socket.on("connect", function() {
250 250
             self.connecting = false;
251 251
             self.emitter.emit("connect", "connect");
  252
+
  253
+            if (self.onConnect)
  254
+                self.onConnect();
  255
+
252 256
             self._createStreams(self.socket);
253 257
 
254 258
             if (firstTask) {
2  package.json
... ...
@@ -1,7 +1,7 @@
1 1
 {
2 2
   "name": "jsftp",
3 3
   "id": "jsftp",
4  
-  "version": "0.4.7",
  4
+  "version": "0.4.9",
5 5
   "description": "A sane FTP client implementation for NodeJS",
6 6
   "keywords": [ "ftp", "protocol", "files", "server", "client", "async" ],
7 7
   "author": "Sergi Mansilla <sergi.mansilla@gmail.com> (http://sergimansilla.com)",
14  test/jsftp_test.js
@@ -364,5 +364,19 @@ describe("jsftp test suite", function() {
364 364
             });
365 365
         });
366 366
     });
  367
+
  368
+    it("test attach event handlers: connect", function(_next) {
  369
+        var clientOnConnect = function() {
  370
+            client.auth(FTPCredentials.user, FTPCredentials.pass, function(err) {
  371
+                assert.ok(!err);
  372
+                client.destroy();
  373
+                _next();
  374
+            });
  375
+        };
  376
+
  377
+        FTPCredentials.onConnect = clientOnConnect;
  378
+
  379
+        var client = new Ftp(FTPCredentials);
  380
+    });
367 381
 });
368 382
 

0 notes on commit c3dee03

Please sign in to comment.
Something went wrong with that request. Please try again.