From eb9525f29392b6afd0e041334a733c3ae34467a7 Mon Sep 17 00:00:00 2001 From: Luke Woodward Date: Sun, 20 Mar 2016 08:31:15 -0500 Subject: [PATCH] Assign the SSH client to this object immediately --- lib/client.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/client.js b/lib/client.js index 6f96850..73998c4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -58,41 +58,40 @@ Client.prototype.sftp = function(callback) { } var self = this; - var ssh = new Connection(); - ssh.on('connect', function() { + this.__ssh = new Connection(); + this.__ssh.on('connect', function() { self.emit('connect'); }); - ssh.on('ready', function() { + this.__ssh.on('ready', function() { self.emit('ready'); - ssh.sftp(function(err, sftp) { + self.__ssh.sftp(function(err, sftp) { if (err) throw err; // save for reuse self.__sftp = sftp; callback(err, sftp); }); }); - ssh.on('error', function(err) { + this.__ssh.on('error', function(err) { self.emit('error', err); callback(err); }); - ssh.on('end', function() { + this.__ssh.on('end', function() { self.emit('end'); }); - ssh.on('close', function() { + this.__ssh.on('close', function() { self.emit('close'); }); - ssh.on('keyboard-interactive', function(name, instructions, instructionsLang, prompts, finish) { + this.__ssh.on('keyboard-interactive', function(name, instructions, instructionsLang, prompts, finish) { self.emit('keyboard-interactive', name, instructions, instructionsLang, prompts, finish); }); - ssh.on('change password', function(message, language, done) { + this.__ssh.on('change password', function(message, language, done) { self.emit('change password', message, language, done); }); - ssh.on('tcp connection', function(details, accept, reject) { + this.__ssh.on('tcp connection', function(details, accept, reject) { self.emit('tcp connection', details, accept, reject); }); - ssh.connect(remote); - this.__ssh = ssh; + this.__ssh.connect(remote); }; Client.prototype.close = function() { if (this.__sftp) {