Permalink
Browse files

Move error handler to before socket connecting

  • Loading branch information...
sergi committed Nov 21, 2012
1 parent f44ae03 commit 5f09ad10532040bbadb58874a0d48067c831d890
Showing with 13 additions and 2 deletions.
  1. +13 −2 lib/jsftp.js
View
@@ -116,7 +116,6 @@ Ftp.getPasvPort = function(text) {
var input = function(next, stop) {
_socket.on("data", next);
_socket.on("end", stop);
- _socket.on("error", stop);
_socket.on("close", stop);
};
@@ -144,7 +143,10 @@ Ftp.getPasvPort = function(text) {
// Stream of FTP commands from the client.
S.append(S.list(null), function(next, stop) { cmd = next; })
)
- (parse, function() { self.emitter.emit("disconnect", "disconnect"); });
+ (parse, function(hadError) {
+ if (!hadError) // Error case handled by error event.
+ self.emitter.emit("disconnect", "Ftp disconnected.");
+ });
if (this.waitingForEnqueue.length > 0) {
this.cmdQueue._update.apply(null, this.waitingForEnqueue);
@@ -247,6 +249,15 @@ Ftp.getPasvPort = function(text) {
self.destroy();
});
+ this.socket.on("error", function(err) {
+ var errString = "Error on ftp socket: " + err;
+ self.emitter.emit("disconnect", errString);
+
+ // We still want the error to appearin the logs if we are not in debug mode.
+ if (!DEBUG_MODE)
+ console.error(errString);
+ });
+
this.socket.on("connect", function() {
self.connecting = false;
self.emitter.emit("connect", "connect");

0 comments on commit 5f09ad1

Please sign in to comment.