From 1b3150bf8c40604595919b5671d04c00aab14c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20Pe=CC=81rez?= Date: Sun, 26 Feb 2017 16:31:01 +0100 Subject: [PATCH 1/2] Completing timeout support. --- lib/jsftp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/jsftp.js b/lib/jsftp.js index d48c2de..505bd6c 100644 --- a/lib/jsftp.js +++ b/lib/jsftp.js @@ -126,6 +126,7 @@ Ftp.prototype._createSocket = function(port, host, firstAction) { this.authenticated = false; this.socket = Net.createConnection(port, host, firstAction || NOOP); + this.socket.setTimeout(self.timeout || TIMEOUT); this.socket.on('connect', this.reemit('connect')); this.socket.on('timeout', this.reemit('timeout')); From c6923c83662ff65c9f1226ebd1d50cd0aa2d00ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20Pe=CC=81rez?= Date: Sun, 26 Feb 2017 17:31:15 +0100 Subject: [PATCH 2/2] Catching an unhandled error to avoid a break. --- lib/jsftp.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/jsftp.js b/lib/jsftp.js index 505bd6c..c34a0f5 100644 --- a/lib/jsftp.js +++ b/lib/jsftp.js @@ -115,6 +115,8 @@ Ftp.prototype.reemit = function(event) { }; Ftp.prototype._createSocket = function(port, host, firstAction) { + var self = this; + if (this.socket && this.socket.destroy) { this.socket.destroy(); } @@ -125,14 +127,15 @@ Ftp.prototype._createSocket = function(port, host, firstAction) { this.resParser = new ResponseParser(); this.authenticated = false; - this.socket = Net.createConnection(port, host, firstAction || NOOP); + this.socket = Net.createConnection(port, host, firstAction || NOOP) + .on('error', (err) => self.emit('error', err)); + this.socket.setTimeout(self.timeout || TIMEOUT); this.socket.on('connect', this.reemit('connect')); this.socket.on('timeout', this.reemit('timeout')); this.pipeline = combine(this.socket, this.resParser); - var self = this; this.pipeline.on('data', function(data) { self.emit('data', data);