From a613386ec4f1ca05e6d0a03ba371425f1933c4dc Mon Sep 17 00:00:00 2001 From: Yuval Shkolar Date: Sun, 4 Dec 2016 14:22:58 +0200 Subject: [PATCH 1/3] Checking if connection ended before ready --- lib/client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/client.js b/lib/client.js index ef80890..968d3b2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -11,6 +11,7 @@ function Client(options) { this._options = options || {}; this.remote = {}; + this._isConnectionReady = false; } util.inherits(Client, EventEmitter); @@ -72,6 +73,8 @@ Client.prototype.sftp = function(callback) { ssh.sftp(function(err, sftp) { if (err) throw err; + + self._isConnectionReady = false; // save for reuse self.__sftp = sftp; callback(err, sftp); @@ -82,6 +85,11 @@ Client.prototype.sftp = function(callback) { callback(err); }); ssh.on('end', function() { + if (!self._isConnectionReady = false){ + var err = 'Connection ended before ready'; + self.emit('error', err); + callback(err); + } self.emit('end'); }); ssh.on('close', function() { From 7c4cd2ecefe7ed9fe4f208f99cb2ca57b32d8f3b Mon Sep 17 00:00:00 2001 From: Yuval Shkolar Date: Sun, 4 Dec 2016 15:39:39 +0200 Subject: [PATCH 2/3] oops --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 968d3b2..330bcba 100644 --- a/lib/client.js +++ b/lib/client.js @@ -74,7 +74,7 @@ Client.prototype.sftp = function(callback) { ssh.sftp(function(err, sftp) { if (err) throw err; - self._isConnectionReady = false; + self._isConnectionReady = true; // save for reuse self.__sftp = sftp; callback(err, sftp); From dc2c737c8ff64520025e90c344d705bce3f987fa Mon Sep 17 00:00:00 2001 From: Yuval Shkolar Date: Sun, 4 Dec 2016 17:46:11 +0200 Subject: [PATCH 3/3] oops --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 330bcba..b02a8e9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -85,7 +85,7 @@ Client.prototype.sftp = function(callback) { callback(err); }); ssh.on('end', function() { - if (!self._isConnectionReady = false){ + if (!self._isConnectionReady){ var err = 'Connection ended before ready'; self.emit('error', err); callback(err);