Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Assign the SSH client to this object immediately #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,41 +58,40 @@ Client.prototype.sftp = function(callback) {
}

var self = this;
var ssh = new Connection();
ssh.on('connect', function() {
this.__ssh = new Connection();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var ssh = this._ssh = new Connection();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var ssh = this.__ssh = new Connection();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why __

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use var ssh = this._ssh = new Connection(); like @popomore suggested.

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) {
Expand Down