Skip to content

Commit

Permalink
Merge pull request #134 from 85204/cy/fix_listener
Browse files Browse the repository at this point in the history
fix(connect): remove listener after connect successfully
  • Loading branch information
jyu213 authored Aug 21, 2019
2 parents 58fd0f9 + fae1407 commit 791c491
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,17 @@ SftpClient.prototype.connect = function(config, connectMethod) {
operation.attempt(function(number) {
sftpObj.client[connectMethod]('ready', () => {
sftpObj.client.sftp((err, sftp) => {
if (err) {
reject(new Error(`Failed to connect to server: ${err.message}`));
}
sftpObj.client.removeListener('error', reject);
sftpObj.client.removeListener('end', reject);
sftpObj.client.removeListener('ready', reject);
sftpObj.sftp = sftp;
resolve(sftp);
});
})

.on('end', reject)
.on('error', function () {
operation.retry( new Error());
Expand Down

0 comments on commit 791c491

Please # to comment.