diff --git a/lib/ssh.js b/lib/ssh.js index dcf1df6..a5fe616 100644 --- a/lib/ssh.js +++ b/lib/ssh.js @@ -192,8 +192,9 @@ SSH.prototype.start = function(options) { self._c.on('error', options.fail); - self._c.on('ready', function() { + function ready() { self._c.removeListener('error', options.fail); + self._c.removeListener('ready', ready); options.success(); if (self._commands.length > 0) { @@ -201,7 +202,8 @@ SSH.prototype.start = function(options) { } else { self._c.end(); } - }); + } + self._c.on('ready', ready); if (self.pass && !self.key) { self._c.connect({ host: self.host, @@ -314,4 +316,4 @@ SSH.prototype.off = function(event, callback) { return this; }; -module.exports = SSH; \ No newline at end of file +module.exports = SSH;