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

Checking if connection ended before ready #81

Open
wants to merge 3 commits 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
8 changes: 8 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Client(options) {
this._options = options || {};

this.remote = {};
this._isConnectionReady = false;
}
util.inherits(Client, EventEmitter);

Expand Down Expand Up @@ -72,6 +73,8 @@ Client.prototype.sftp = function(callback) {

ssh.sftp(function(err, sftp) {
if (err) throw err;

self._isConnectionReady = true;
// save for reuse
self.__sftp = sftp;
callback(err, sftp);
Expand All @@ -82,6 +85,11 @@ Client.prototype.sftp = function(callback) {
callback(err);
});
ssh.on('end', function() {
if (!self._isConnectionReady){
var err = 'Connection ended before ready';
self.emit('error', err);
callback(err);
}
self.emit('end');
});
ssh.on('close', function() {
Expand Down