Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ssh2-sftp-client

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh2-sftp-client - npm Package Compare versions

Comparing version 9.0.1 to 9.0.2

2

package.json
{
"name": "ssh2-sftp-client",
"version": "9.0.1",
"version": "9.0.2",
"description": "ssh2 sftp client for node",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -21,3 +21,3 @@ 'use strict';

constructor(clientName) {
this.version = '9.0.0';
this.version = '9.0.2';
this.client = new Client();

@@ -35,3 +35,3 @@ this.sftp = undefined;

this.client.on('close', () => {
if (this.endCalled || this.closeHandled) {
if (this.endCalled || this.errorHandled || this.closeHandled) {
// we are processing an expected end event or close event handled elsewhere

@@ -46,3 +46,3 @@ this.debugMsg('Global: Ignoring handled close event');

this.client.on('end', () => {
if (this.endCalled || this.endHandled) {
if (this.endCalled || this.errorHandled || this.endHandled) {
// end event expected or handled elsewhere

@@ -101,15 +101,9 @@ this.debugMsg('Global: Ignoring hanlded end event');

case 'ENOTFOUND':
msg =
`${name}: ${err.level} error. ` +
`Address lookup failed for host ${err.hostname}${retry}`;
msg = `${name}: Address lookup failed for host${retry}`;
break;
case 'ECONNREFUSED':
msg =
`${name}: ${err.level} error. Remote host at ` +
`${err.address} refused connection${retry}`;
msg = `${name}: Remote host refused connection${retry}`;
break;
case 'ECONNRESET':
msg =
`${name}: Remote host has reset the connection: ` +
`${err.message}${retry}`;
msg = `${name}: Remote host has reset the connection: ${err.message}${retry}`;
break;

@@ -121,3 +115,3 @@ default:

}
let newError = new Error(msg);
const newError = new Error(msg);
newError.code = code;

@@ -167,5 +161,3 @@ newError.custom = true;

doReady = () => {
this.debugMsg(
'getConnection ready listener: got connection - promise resolved'
);
this.debugMsg('getConnection ready listener: got connection - promise resolved');
resolve(true);

@@ -178,3 +170,2 @@ };

removeTempListeners(this, listeners, 'getConnection');
this._resetEventFlags();
});

@@ -187,3 +178,2 @@ }

if (err) {
this.client.end();
reject(this.fmtError(err, 'getSftpChannel', err.code));

@@ -219,6 +209,3 @@ } else {

this.debugMsg('connect: Debugging turned on');
this.debugMsg(
`ssh2-sftp-client Version: ${this.version} `,
process.versions
);
this.debugMsg(`ssh2-sftp-client Version: ${this.version} `, process.versions);
}

@@ -232,6 +219,6 @@ if (this.sftp) {

}
let retryOpts = {
retries: config.retries || 1,
factor: config.factor || 2,
minTimeout: config.retry_minTimeout || 25000,
const retryOpts = {
retries: config.retries ?? 1,
factor: config.factor ?? 2,
minTimeout: config.retry_minTimeout ?? 25000,
};

@@ -247,31 +234,22 @@ await promiseRetry(retryOpts, async (retry, attempt) => {

case 'ERR_SOCKET_BAD_PORT':
throw err;
case undefined: {
if (
err.message.endsWith(
'All configured authentication methods failed'
)
) {
throw this.fmtError(
err.message,
'getConnection',
errorCode.badAuth
);
}
retry(err);
break;
throw err;
case undefined: {
if (err.message.endsWith('All configured authentication methods failed')) {
throw this.fmtError(err.message, 'getConnection', errorCode.badAuth);
}
default:
retry(err);
retry(err);
break;
}
default:
retry(err);
}
}
});
let sftp = await this.getSftpChannel();
const sftp = await this.getSftpChannel();
return sftp;
} catch (err) {
this.end();
await this.end();
throw err.custom ? err : this.fmtError(err, 'connect');
} finally {
removeTempListeners(this, listeners, 'connect');
this._resetEventFlags();
}

@@ -300,5 +278,3 @@ }

} else {
reject(
this.fmtError(`${err.message} ${rPath}`, 'realPath', err.code)
);
reject(this.fmtError(`${err.message} ${rPath}`, 'realPath', err.code));
}

@@ -324,3 +300,2 @@ }

removeTempListeners(this, listeners, 'realPath');
this._resetEventFlags();
}

@@ -352,9 +327,3 @@ }

if (err.code === 2 || err.code === 4) {
reject(
this.fmtError(
`No such file: ${aPath}`,
'_stat',
errorCode.notexist
)
);
reject(this.fmtError(`No such file: ${aPath}`, '_stat', errorCode.notexist));
} else {

@@ -397,3 +366,2 @@ reject(this.fmtError(`${err.message} ${aPath}`, '_stat', err.code));

removeTempListeners(this, listeners, 'stat');
this._resetEventFlags();
}

@@ -455,3 +423,2 @@ }

removeTempListeners(this, listeners, 'exists');
this._resetEventFlags();
}

@@ -477,5 +444,3 @@ }

if (err) {
reject(
this.fmtError(`${err.message} ${remotePath}`, 'list', err.code)
);
reject(this.fmtError(`${err.message} ${remotePath}`, 'list', err.code));
} else {

@@ -517,8 +482,5 @@ const reg = /-/gi;

} catch (e) {
throw e.custom
? e
: this.fmtError(`${e.message} ${remotePath}`, 'list', e.code);
throw e.custom ? e : this.fmtError(`${e.message} ${remotePath}`, 'list', e.code);
} finally {
removeTempListeners(this, listeners, 'list');
this._resetEventFlags();
}

@@ -614,8 +576,5 @@ }

} catch (e) {
throw e.custom
? e
: this.fmtError(`${e.message} ${remotePath}`, 'get', e.code);
throw e.custom ? e : this.fmtError(`${e.message} ${remotePath}`, 'get', e.code);
} finally {
removeTempListeners(this, listeners, 'get');
this._resetEventFlags();
}

@@ -638,5 +597,3 @@ }

if (err) {
reject(
this.fmtError(`${err.message} Remote: ${rPath} Local: ${lPath}`)
);
reject(this.fmtError(`${err.message} Remote: ${rPath} Local: ${lPath}`));
}

@@ -655,5 +612,3 @@ resolve(`${rPath} was successfully download to ${lPath}!`);

if (ftype !== '-') {
const msg = `${
!ftype ? 'No such file ' : 'Not a regular file'
} ${remotePath}`;
const msg = `${!ftype ? 'No such file ' : 'Not a regular file'} ${remotePath}`;
throw this.fmtError(msg, 'fastGet', errorCode.badPath);

@@ -674,3 +629,2 @@ }

removeTempListeners(this, listeners, 'fastGet');
this._resetEventFlags();
}

@@ -734,3 +688,2 @@ }

removeTempListeners(this, listeners, 'fastPut');
this._resetEventFlags();
}

@@ -783,5 +736,3 @@ }

this.fmtError(
`${err.message} ${
typeof lPath === 'string' ? lPath : '<stream>'
}`,
`${err.message} ${typeof lPath === 'string' ? lPath : '<stream>'}`,
'_put',

@@ -817,3 +768,2 @@ err.code

removeTempListeners(this, listeners, 'put');
this._resetEventFlags();
}

@@ -875,3 +825,2 @@ }

removeTempListeners(this, listeners, 'append');
this._resetEventFlags();
}

@@ -967,3 +916,2 @@ }

removeTempListeners(this, listeners, 'append');
this._resetEventFlags();
}

@@ -1009,5 +957,3 @@ }

for (const f of files) {
promiseList.push(
this._delete(`${p}${this.remotePathSep}${f.name}`)
);
promiseList.push(this._delete(`${p}${this.remotePathSep}${f.name}`));
}

@@ -1048,3 +994,2 @@ await Promise.all(promiseList);

removeTempListeners(this, listeners, 'rmdir');
this._resetEventFlags();
}

@@ -1071,5 +1016,3 @@ }

} else {
reject(
this.fmtError(`${err.message} ${rPath}`, 'delete', err.code)
);
reject(this.fmtError(`${err.message} ${rPath}`, 'delete', err.code));
}

@@ -1092,3 +1035,2 @@ }

removeTempListeners(this, listeners, 'delete');
this._resetEventFlags();
}

@@ -1134,10 +1076,5 @@ }

? err
: this.fmtError(
`${err.message} ${fromPath} ${toPath}`,
'rename',
err.code
);
: this.fmtError(`${err.message} ${fromPath} ${toPath}`, 'rename', err.code);
} finally {
removeTempListeners(this, listeners, 'rename');
this._resetEventFlags();
}

@@ -1184,10 +1121,5 @@ }

? err
: this.fmtError(
`${err.message} ${fromPath} ${toPath}`,
'posixRename',
err.code
);
: this.fmtError(`${err.message} ${fromPath} ${toPath}`, 'posixRename', err.code);
} finally {
removeTempListeners(this, listeners, 'posixRename');
this._resetEventFlags();
}

@@ -1229,3 +1161,2 @@ }

removeTempListeners(this, listeners, 'chmod');
this._resetEventFlags();
}

@@ -1305,5 +1236,3 @@ }

} else {
this.debugMsg(
`uploadDir: File ignored: ${e.name} not a regular file`
);
this.debugMsg(`uploadDir: File ignored: ${e.name} not a regular file`);
}

@@ -1331,3 +1260,2 @@ await Promise.all(fileUploads);

removeTempListeners(this, listeners, 'chmod');
this._resetEventFlags();
}

@@ -1394,5 +1322,3 @@ }

} else {
this.debugMsg(
`downloadDir: File ignored: ${f.name} not regular file`
);
this.debugMsg(`downloadDir: File ignored: ${f.name} not regular file`);
}

@@ -1419,3 +1345,2 @@ }

removeTempListeners(this, listeners, 'downloadDir');
this._resetEventFlags();
}

@@ -1445,8 +1370,5 @@ }

} catch (err) {
throw err.custom
? err
: this.fmtError(err.message, 'createReadStream', err.code);
throw err.custom ? err : this.fmtError(err.message, 'createReadStream', err.code);
} finally {
removeTempListeners(this, listeners, 'createReadStreame');
this._resetEventFlags();
}

@@ -1476,8 +1398,5 @@ }

} catch (err) {
throw err.custom
? err
: this.fmtError(err.message, 'createWriteStream', err.code);
throw err.custom ? err : this.fmtError(err.message, 'createWriteStream', err.code);
} finally {
removeTempListeners(this, listeners, 'createWriteStream');
this._resetEventFlags();
}

@@ -1531,7 +1450,3 @@ }

if (srcExists !== '-') {
throw this.fmtError(
`Source not a file ${srcPath}`,
'rcopy',
errorCode.badPath
);
throw this.fmtError(`Source not a file ${srcPath}`, 'rcopy', errorCode.badPath);
}

@@ -1547,3 +1462,3 @@ const dstPath = await normalizeRemotePath(this, dst);

}
return await this._rcopy(srcPath, dstPath);
return this._rcopy(srcPath, dstPath);
} catch (err) {

@@ -1553,3 +1468,2 @@ throw err.custom ? err : this.fmtError(err, 'rcopy');

removeTempListeners(this, listeners, 'rcopy');
this._resetEventFlags();
}

@@ -1575,4 +1489,8 @@ }

this.on('close', endCloseHandler);
if (haveConnection(this, 'end', reject)) {
if (this.client) {
this.client.end();
} else {
// no actual connection exists - just resolve
this.debugMsg('end: Called when no connection active');
resolve(true);
}

@@ -1583,3 +1501,2 @@ }).finally(() => {

this.endCalled = false;
this._resetEventFlags();
});

@@ -1586,0 +1503,0 @@ }

@@ -13,9 +13,10 @@ const fs = require('fs');

function errorListener(client, name, reject) {
let fn = (err) => {
const fn = (err) => {
if (client.endCalled || client.errorHandled) {
// error already handled or expected - ignore
client.debugMsg(`${name} errorListener - ignoring handled error`);
return;
}
client.errorHandled = true;
let newError = new Error(`${name}: ${err.message}`);
const newError = new Error(`${name}: ${err.message}`);
newError.code = err.code;

@@ -32,15 +33,19 @@ if (reject) {

function endListener(client, name, reject) {
let fn = function () {
if (client.endCalled || client.endHandled) {
const fn = function () {
client.sftp = undefined;
if (client.endCalled || client.endHandled || client.errorHandled) {
// end event already handled - ignore
client.debugMsg(`${name} endListener - ignoring handled error`);
return;
}
client.sftp = undefined;
client.endHandled = true;
let err = new Error(`${name} Unexpected end event raised`);
if (reject) {
reject(err);
} else {
throw err;
}
client.debugMsg(`${name} Unexpected end event - ignoring`);
// Don't reject/throw error, just log it and move on
// after invalidating the connection
// const err = new Error(`${name} Unexpected end event raised`);
// if (reject) {
// reject(err);
// } else {
// throw err;
// }
};

@@ -51,15 +56,24 @@ return fn;

function closeListener(client, name, reject) {
let fn = function () {
if (client.endCalled || client.closeHandled) {
const fn = function () {
client.sftp = undefined;
if (
client.endCalled ||
client.closeHandled ||
client.errorHandled ||
client.endHandled
) {
// handled or expected close event - ignore
client.debugMsg(`${name} closeListener - ignoring handled error`);
return;
}
client.sftp = undefined;
client.closeHandled = true;
let err = new Error(`${name}: Unexpected close event raised`);
if (reject) {
reject(err);
} else {
throw err;
}
client.debugMsg(`${name} Unexpected close event raised - ignoring`);
// Don't throw/reject on close events. Just invalidate the connection
// and move on.
// const err = new Error(`${name}: Unexpected close event raised`);
// if (reject) {
// reject(err);
// } else {
// throw err;
// }
};

@@ -70,3 +84,3 @@ return fn;

function addTempListeners(client, name, reject) {
let listeners = {
const listeners = {
end: endListener(client, name, reject),

@@ -79,2 +93,3 @@ close: closeListener(client, name, reject),

client.on('error', listeners.error);
client._resetEventFlags();
return listeners;

@@ -114,5 +129,3 @@ }

} else {
let err = new Error(
`Bad path: ${filePath}: target must be a file or directory`
);
const err = new Error(`Bad path: ${filePath}: target must be a file or directory`);
err.code = errorCode.badPath;

@@ -258,3 +271,3 @@ throw err;

if (!client.sftp) {
let newError = new Error(`${name}: No SFTP connection available`);
const newError = new Error(`${name}: No SFTP connection available`);
newError.code = errorCode.connect;

@@ -261,0 +274,0 @@ if (reject) {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc