Socket
Socket
Sign inDemoInstall

ssh2-sftp-client

Package Overview
Dependencies
43
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0 to 6.0.1

9

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

@@ -12,3 +12,4 @@ "main": "src/index.js",

"scripts": {
"test": "mocha"
"test": "mocha",
"coverage": "nyc npm run test"
},

@@ -27,3 +28,4 @@ "author": "Tim Cross",

"promise-retry": "^2.0.1",
"ssh2": "^0.8.9"
"ssh2": "^0.8.9",
"winston": "^3.3.3"
},

@@ -38,4 +40,5 @@ "devDependencies": {

"moment": "^2.29.1",
"nyc": "^15.1.0",
"through2": "^4.0.2"
}
}

@@ -10,6 +10,12 @@ /**

const concat = require('concat-stream');
//const retry = require('retry');
const promiseRetry = require('promise-retry');
const {join, parse} = require('path');
const utils = require('./utils');
const {
fmtError,
addTempListeners,
removeTempListeners,
haveConnection,
normalizeRemotePath,
localExists
} = require('./utils');
const {errorCode} = require('./constants');

@@ -42,3 +48,3 @@

if (!this.errorHandled) {
throw utils.formatError(
throw fmtError(
`Unexpected error: ${err.message}`,

@@ -97,21 +103,41 @@ 'global-error-handler',

sftpConnect(config) {
let connectReady;
return new Promise((resolve, reject) => {
let connectReady = () => {
addTempListeners(this, 'sftpConnect', reject);
connectReady = () => {
this.client.sftp((err, sftp) => {
if (err) {
this.debugMsg(`SFTP channel error: ${err.message} ${err.code}`);
reject(utils.formatError(err, 'sftpConnect', err.code));
reject(fmtError(err, 'sftpConnect', err.code));
} else {
//this.sftp = sftp;
this.debugMsg('SFTP channel established');
resolve(sftp);
}
this.client.removeListener('ready', connectReady);
});
};
utils.addTempListeners(this, 'sftpConnect', reject);
// addTempListeners(this, 'sftpConnect', reject);
this.client.on('ready', connectReady).connect(config);
}).finally((rsp) => {
this.removeListener('ready', connectReady);
removeTempListeners(this.client);
return rsp;
});
}
retryConnect(config) {
connect(config) {
if (config.debug) {
this.debug = config.debug;
this.debugMsg('Debugging turned on');
}
if (this.sftp) {
this.debugMsg('Already connected - reject');
return Promise.reject(
fmtError(
'An existing SFTP connection is already defined',
'connect',
errorCode.connect
)
);
}
return promiseRetry(

@@ -121,3 +147,2 @@ (retry, attempt) => {

return this.sftpConnect(config).catch((err) => {
utils.removeTempListeners(this.client);
retry(err);

@@ -131,28 +156,7 @@ });

}
);
).then((sftp) => {
this.sftp = sftp;
});
}
async connect(config) {
try {
if (config.debug) {
this.debug = config.debug;
this.debugMsg('Debugging turned on');
}
if (this.sftp) {
this.debugMsg('Already connected - reject');
throw utils.formatError(
'An existing SFTP connection is already defined',
'connect',
errorCode.connect
);
}
//this.sftp = await this.sftpConnect(config);
this.sftp = await this.retryConnect(config);
this.debugMsg('SFTP Connection established');
utils.removeTempListeners(this.client);
} catch (err) {
throw utils.formatError(err.message, 'connect', err.errorCode);
}
}
/**

@@ -173,4 +177,4 @@ * @async

this.debugMsg(`realPath -> ${remotePath}`);
utils.addTempListeners(this, 'realPath', reject);
if (utils.haveConnection(this, 'realPath', reject)) {
addTempListeners(this, 'realPath', reject);
if (haveConnection(this, 'realPath', reject)) {
this.sftp.realpath(remotePath, (err, absPath) => {

@@ -183,7 +187,3 @@ if (err) {

reject(
utils.formatError(
`${err.message} ${remotePath}`,
'realPath',
err.code
)
fmtError(`${err.message} ${remotePath}`, 'realPath', err.code)
);

@@ -194,5 +194,7 @@ }

resolve(absPath);
utils.removeTempListeners(this.client);
});
}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -215,3 +217,3 @@ }

this.debugMsg(`stat -> ${aPath}`);
utils.addTempListeners(this, 'stat', reject);
addTempListeners(this, 'stat', reject);
this.sftp.stat(aPath, (err, stats) => {

@@ -222,3 +224,3 @@ if (err) {

reject(
utils.formatError(
fmtError(
`No such file: ${remotePath}`,

@@ -231,7 +233,3 @@ '_stat',

reject(
utils.formatError(
`${err.message} ${remotePath}`,
'_stat',
err.code
)
fmtError(`${err.message} ${remotePath}`, '_stat', err.code)
);

@@ -257,4 +255,6 @@ }

}
utils.removeTempListeners(this.client);
});
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -264,7 +264,11 @@ };

try {
utils.haveConnection(this, 'stat');
let absPath = await utils.normalizeRemotePath(this, remotePath);
haveConnection(this, 'stat');
let absPath = await normalizeRemotePath(this, remotePath);
return _stat(absPath);
} catch (err) {
return utils.handleError(err, 'stat');
if (err.custom) {
throw err;
} else {
throw fmtError(err, 'stat', err.code);
}
}

@@ -286,7 +290,7 @@ }

try {
if (utils.haveConnection(this, 'exists')) {
if (haveConnection(this, 'exists')) {
if (remotePath === '.') {
return 'd';
}
let absPath = await utils.normalizeRemotePath(this, remotePath);
let absPath = await normalizeRemotePath(this, remotePath);
try {

@@ -316,3 +320,7 @@ this.debugMsg(`exists -> ${absPath}`);

} catch (err) {
return utils.handleError(err, 'exists');
if (err.custom) {
throw err;
} else {
throw fmtError(err, 'exists', err.code);
}
}

@@ -337,16 +345,10 @@ }

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'list', reject)) {
if (haveConnection(this, 'list', reject)) {
const reg = /-/gi;
this.debugMsg(`list -> ${remotePath} filter -> ${pattern}`);
utils.addTempListeners(this, 'list', reject);
addTempListeners(this, 'list', reject);
this.sftp.readdir(remotePath, (err, fileList) => {
if (err) {
this.debugMsg(`list error ${err.message} code: ${err.code}`);
reject(
utils.formatError(
`${err.message} ${remotePath}`,
'list',
err.code
)
);
reject(fmtError(`${err.message} ${remotePath}`, 'list', err.code));
} else {

@@ -384,5 +386,7 @@ this.debugMsg('list <- ', fileList);

}
utils.removeTempListeners(this.client);
});
}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -407,12 +411,8 @@ }

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'get', reject)) {
if (haveConnection(this, 'get', reject)) {
this.debugMsg(`get -> ${remotePath} `, options);
utils.addTempListeners(this, 'get', reject);
addTempListeners(this, 'get', reject);
let rdr = this.sftp.createReadStream(remotePath, options);
rdr.once('error', (err) => {
utils.removeListeners(rdr);
reject(
utils.formatError(`${err.message} ${remotePath}`, 'get', err.code)
);
utils.removeTempListeners(this.client);
reject(fmtError(`${err.message} ${remotePath}`, 'get', err.code));
});

@@ -425,3 +425,2 @@ if (dst === undefined) {

resolve(buff);
utils.removeTempListeners(this.client);
});

@@ -440,5 +439,4 @@ rdr.pipe(concatStream);

wtr.once('error', (err) => {
utils.removeListeners(rdr);
reject(
utils.formatError(
fmtError(
`${err.message} ${typeof dst === 'string' ? dst : ''}`,

@@ -452,6 +450,4 @@ 'get',

}
utils.removeTempListeners(this.client);
});
wtr.once('finish', () => {
utils.removeListeners(rdr);
if (options.autoClose === false) {

@@ -465,3 +461,2 @@ rdr.destroy();

}
utils.removeTempListeners(this.client);
});

@@ -471,2 +466,5 @@ rdr.pipe(wtr);

}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -496,5 +494,3 @@ }

: `Not a regular file ${remotePath}`;
return Promise.reject(
utils.formatError(msg, 'fastGet', errorCode.badPath)
);
return Promise.reject(fmtError(msg, 'fastGet', errorCode.badPath));
}

@@ -504,3 +500,3 @@ })

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'fastGet', reject)) {
if (haveConnection(this, 'fastGet', reject)) {
this.debugMsg(

@@ -510,7 +506,7 @@ `fastGet -> remote: ${remotePath} local: ${localPath} `,

);
utils.addTempListeners(this, 'fastGet', reject);
addTempListeners(this, 'fastGet', reject);
this.sftp.fastGet(remotePath, localPath, options, (err) => {
if (err) {
this.debugMsg(`fastGet error ${err.message} code: ${err.code}`);
reject(utils.formatError(err, 'fastGet'));
reject(fmtError(err, 'fastGet'));
}

@@ -520,5 +516,7 @@ resolve(

);
utils.removeTempListeners(this.client);
});
}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -543,4 +541,3 @@ });

this.debugMsg(`fastPut -> local ${localPath} remote ${remotePath}`);
return utils
.localExists(localPath)
return localExists(localPath)
.then((localStatus) => {

@@ -551,7 +548,3 @@ this.debugMsg(`fastPut <- localStatus ${localStatus}`);

return Promise.reject(
utils.formatError(
`Bad path ${localPath}`,
'fastPut',
errorCode.badPath
)
fmtError(`Bad path ${localPath}`, 'fastPut', errorCode.badPath)
);

@@ -564,7 +557,3 @@ }

reject(
utils.formatError(
`${err.message} ${localPath}`,
'fastPut',
err.code
)
fmtError(`${err.message} ${localPath}`, 'fastPut', err.code)
);

@@ -580,3 +569,3 @@ } else {

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'fastPut', reject)) {
if (haveConnection(this, 'fastPut', reject)) {
this.debugMsg(

@@ -587,3 +576,3 @@ `fastPut -> local: ${localPath} remote: ${remotePath} opts: ${JSON.stringify(

);
utils.addTempListeners(this, 'fastPut', reject);
addTempListeners(this, 'fastPut', reject);
this.sftp.fastPut(localPath, remotePath, options, (err) => {

@@ -593,3 +582,3 @@ if (err) {

reject(
utils.formatError(
fmtError(
`${err.message} Local: ${localPath} Remote: ${remotePath}`,

@@ -607,7 +596,6 @@ 'fastPut',

}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});
})
.then((msg) => {
utils.removeTempListeners(this.client);
return msg;
});

@@ -634,4 +622,3 @@ }

);
return utils
.localExists(typeof localSrc === 'string' ? localSrc : 'dummy')
return localExists(typeof localSrc === 'string' ? localSrc : 'dummy')
.then((localStatus) => {

@@ -641,3 +628,3 @@ if (typeof localSrc === 'string' && localStatus !== '-') {

return Promise.reject(
utils.formatError(`Bad path ${localSrc}`, 'put', errorCode.badPath)
fmtError(`Bad path ${localSrc}`, 'put', errorCode.badPath)
);

@@ -654,3 +641,3 @@ }

reject(
utils.formatError(
fmtError(
`Permission denied ${localSrc}`,

@@ -675,17 +662,9 @@ 'put',

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'put', reject)) {
utils.addTempListeners(this, 'put', reject);
if (haveConnection(this, 'put', reject)) {
addTempListeners(this, 'put', reject);
let stream = this.sftp.createWriteStream(remotePath, options);
stream.once('error', (err) => {
reject(
utils.formatError(
`${err.message} ${remotePath}`,
'put',
err.code
)
);
utils.removeTempListeners(this.client);
reject(fmtError(`${err.message} ${remotePath}`, 'put', err.code));
});
stream.once('finish', () => {
utils.removeListeners(stream);
if (options.autoClose === false) {

@@ -695,3 +674,2 @@ stream.destroy();

resolve(`Uploaded data stream to ${remotePath}`);
utils.removeTempListeners(this.client);
});

@@ -711,5 +689,4 @@ if (localSrc instanceof Buffer) {

rdr.once('error', (err) => {
utils.removeListeners(stream);
reject(
utils.formatError(
fmtError(
`${err.message} ${

@@ -725,3 +702,2 @@ typeof localSrc === 'string' ? localSrc : ''

}
utils.removeTempListeners(this.client);
});

@@ -731,2 +707,5 @@ rdr.pipe(stream);

}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -746,27 +725,17 @@ });

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'append', reject)) {
if (haveConnection(this, 'append', reject)) {
if (typeof input === 'string') {
reject(
utils.formatError('Cannot append one file to another', 'append')
);
reject(fmtError('Cannot append one file to another', 'append'));
} else {
this.debugMsg(`append -> remote: ${remotePath} `, options);
utils.addTempListeners(this, 'append', reject);
addTempListeners(this, 'append', reject);
options.flags = 'a';
let stream = this.sftp.createWriteStream(remotePath, options);
stream.once('error', (err) => {
utils.removeListeners(stream);
reject(
utils.formatError(
`${err.message} ${remotePath}`,
'append',
err.code
)
fmtError(`${err.message} ${remotePath}`, 'append', err.code)
);
utils.removeTempListeners(this.client);
});
stream.once('finish', () => {
utils.removeListeners(stream);
resolve(`Appended data to ${remotePath}`);
utils.removeTempListeners(this.client);
});

@@ -780,2 +749,5 @@ if (input instanceof Buffer) {

}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -797,13 +769,13 @@ }

this.debugMsg(`mkdir -> ${p}`);
utils.addTempListeners(this, 'mkdir', reject);
addTempListeners(this, 'mkdir', reject);
this.sftp.mkdir(p, (err) => {
if (err) {
this.debugMsg(`mkdir error ${err.message} code: ${err.code}`);
reject(
utils.formatError(`${err.message} ${p}`, '_mkdir', err.code)
);
reject(fmtError(`${err.message} ${p}`, '_mkdir', err.code));
}
resolve(`${p} directory created`);
utils.removeTempListeners(this.client);
});
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -813,4 +785,4 @@ };

try {
utils.haveConnection(this, 'mkdir');
let rPath = await utils.normalizeRemotePath(this, remotePath);
haveConnection(this, 'mkdir');
let rPath = await normalizeRemotePath(this, remotePath);
if (!recursive) {

@@ -828,3 +800,7 @@ return _mkdir(rPath);

} catch (err) {
return utils.handleError(`${err.message} ${remotePath}`, 'mkdir');
if (err.custom) {
throw err;
} else {
throw fmtError(`${err.message} ${remotePath}`, 'mkdir', err.code);
}
}

@@ -847,13 +823,13 @@ }

this.debugMsg(`rmdir -> ${p}`);
utils.addTempListeners(this, 'rmdir', reject);
addTempListeners(this, 'rmdir', reject);
this.sftp.rmdir(p, (err) => {
if (err) {
this.debugMsg(`rmdir error ${err.message} code: ${err.code}`);
reject(
utils.formatError(`${err.message} ${p}`, '_rmdir', err.code)
);
reject(fmtError(`${err.message} ${p}`, '_rmdir', err.code));
}
resolve('Successfully removed directory');
utils.removeTempListeners(this.client);
});
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -863,4 +839,4 @@ };

try {
utils.haveConnection(this, 'rmdir');
let absPath = await utils.normalizeRemotePath(this, remotePath);
haveConnection(this, 'rmdir');
let absPath = await normalizeRemotePath(this, remotePath);
if (!recursive) {

@@ -884,3 +860,7 @@ return _rmdir(absPath);

} catch (err) {
return utils.handleError(err, 'rmdir');
if (err.custom) {
throw err;
} else {
throw fmtError(err, 'rmdir', err.code);
}
}

@@ -902,5 +882,5 @@ }

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'delete', reject)) {
if (haveConnection(this, 'delete', reject)) {
this.debugMsg(`delete -> ${remotePath}`);
utils.addTempListeners(this, 'delete', reject);
addTempListeners(this, 'delete', reject);
this.sftp.unlink(remotePath, (err) => {

@@ -914,7 +894,3 @@ if (err) {

reject(
utils.formatError(
`${err.message} ${remotePath}`,
'delete',
err.code
)
fmtError(`${err.message} ${remotePath}`, 'delete', err.code)
);

@@ -924,5 +900,7 @@ }

resolve(`Successfully deleted ${remotePath}`);
utils.removeTempListeners(this.client);
});
}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -944,5 +922,5 @@ }

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'rename', reject)) {
if (haveConnection(this, 'rename', reject)) {
this.debugMsg(`rename -> ${fromPath} ${toPath}`);
utils.addTempListeners(this, 'rename', reject);
addTempListeners(this, 'rename', reject);
this.sftp.rename(fromPath, toPath, (err) => {

@@ -952,3 +930,3 @@ if (err) {

reject(
utils.formatError(
fmtError(
`${err.message} From: ${fromPath} To: ${toPath}`,

@@ -961,5 +939,7 @@ 'rename',

resolve(`Successfully renamed ${fromPath} to ${toPath}`);
utils.removeTempListeners(this.client);
});
}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -982,5 +962,5 @@ }

return new Promise((resolve, reject) => {
if (utils.haveConnection(this, 'posixRename', reject)) {
if (haveConnection(this, 'posixRename', reject)) {
this.debugMsg(`posixRename -> ${fromPath} ${toPath}`);
utils.addTempListeners(this, 'posixRename', reject);
addTempListeners(this, 'posixRename', reject);
this.sftp.ext_openssh_rename(fromPath, toPath, (err) => {

@@ -990,3 +970,3 @@ if (err) {

reject(
utils.formatError(
fmtError(
`${err.message} From: ${fromPath} To: ${toPath}`,

@@ -999,5 +979,7 @@ 'posixRename',

resolve(`Successful POSIX rename ${fromPath} to ${toPath}`);
utils.removeTempListeners(this.client);
});
}
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -1019,12 +1001,12 @@ }

this.debugMsg(`chmod -> ${remotePath} ${mode}`);
utils.addTempListeners(this, 'chmod', reject);
addTempListeners(this, 'chmod', reject);
this.sftp.chmod(remotePath, mode, (err) => {
if (err) {
reject(
utils.formatError(`${err.message} ${remotePath}`, 'chmod', err.code)
);
reject(fmtError(`${err.message} ${remotePath}`, 'chmod', err.code));
}
resolve('Successfully change file mode');
utils.removeTempListeners(this.client);
});
}).finally((rsp) => {
removeTempListeners(this.client);
return rsp;
});

@@ -1049,10 +1031,6 @@ }

this.debugMsg(`uploadDir -> ${srcDir} ${dstDir}`);
utils.haveConnection(this, 'uploadDir');
haveConnection(this, 'uploadDir');
let dstStatus = await this.exists(dstDir);
if (dstStatus && dstStatus !== 'd') {
throw utils.formatError(
`Bad path ${dstDir}`,
'uploadDir',
errorCode.badPath
);
throw fmtError(`Bad path ${dstDir}`, 'uploadDir', errorCode.badPath);
}

@@ -1085,3 +1063,7 @@ if (!dstStatus) {

} catch (err) {
return utils.handleError(err, 'uploadDir');
if (err.custom) {
throw err;
} else {
throw fmtError(err, 'uploadDir');
}
}

@@ -1106,11 +1088,7 @@ }

this.debugMsg(`downloadDir -> ${srcDir} ${dstDir}`);
utils.haveConnection(this, 'downloadDir');
haveConnection(this, 'downloadDir');
let fileList = await this.list(srcDir, filter);
let dstStatus = await utils.localExists(dstDir);
let dstStatus = await localExists(dstDir);
if (dstStatus && dstStatus !== 'd') {
throw utils.formatError(
`Bad path ${dstDir}`,
'downloadDir',
errorCode.badPath
);
throw fmtError(`Bad path ${dstDir}`, 'downloadDir', errorCode.badPath);
}

@@ -1138,3 +1116,7 @@ if (!dstStatus) {

} catch (err) {
return utils.handleError(err, 'downloadDir');
if (err.custom) {
throw err;
} else {
throw fmtError(err, 'downloadDir', err.code);
}
}

@@ -1150,38 +1132,19 @@ }

end() {
let endCloseHandler;
return new Promise((resolve, reject) => {
const endErrorListener = (err) => {
// we don't care about errors at this point
// so do nothiing
this.debugMsg(
`endErrorListener called with ${err.message} and code ${err.code}`
);
this.errorHandled = true;
if (err.code !== 'ECONNRESET') {
reject(utils.formatError(err, 'end'));
} else {
this.debugMsg('Error is ECONNRESET - ignoring error');
}
this.endCalled = true;
addTempListeners(this, 'end', reject);
endCloseHandler = () => {
this.sftp = undefined;
resolve(true);
};
try {
if (!utils.hasListener(this.client, 'error', 'endErrorListener')) {
this.debugMsg('Adding enderrorListener');
this.client.prependListener('error', endErrorListener);
} else {
this.debugMsg('endErrorListener already set');
}
this.endCalled = true;
if (utils.haveConnection(this, 'end', reject)) {
this.debugMsg('Have connection - calling end()');
this.client.end();
} else {
this.debugMsg('No connection - skipping call to end()');
}
resolve(true);
} catch (err) {
utils.handleError(err, 'end', reject);
} finally {
this.sftp = undefined;
this.endCalled = false;
this.on('close', endCloseHandler);
if (haveConnection(this, 'end', reject)) {
this.debugMsg('Have connection - calling end()');
this.client.end();
}
}).finally(() => {
removeTempListeners(this.client);
this.removeListener('close', endCloseHandler);
return true;
});

@@ -1188,0 +1151,0 @@ }

'use strict';
const {prependListener} = require('cluster');
const fs = require('fs');

@@ -16,3 +15,3 @@ const {errorCode} = require('./constants');

*/
function formatError(err, name = 'sftp', eCode, retryCount) {
function fmtError(err, name = 'sftp', eCode, retryCount) {
let msg = '';

@@ -50,5 +49,2 @@ let code = '';

break;
case 'ENOENT':
msg = `${name}: ${err.message}${retry}`;
break;
default:

@@ -65,40 +61,2 @@ msg = `${name}: ${err.message}${retry}`;

/**
* Tests an error to see if it is one which has already been customised
* by this module or not. If not, applies appropriate customisation.
*
* @param {Error} err - an Error object
* @param {String} name - name to be used in customised error message
* @param {Function} reject - If defined, call this function instead of
* throwing the error
* @throws {Error}
*/
function handleError(err, name, reject) {
if (reject) {
if (err.custom) {
reject(err);
} else {
reject(formatError(err, name));
}
} else {
if (err.custom) {
throw err;
} else {
throw formatError(err, name, err.code);
}
}
}
/**
* Remove all ready, error and end listeners.
*
* @param {Emitter} emitter - The emitter object to remove listeners from
*/
function removeListeners(emitter) {
let listeners = emitter.eventNames();
listeners.forEach((name) => {
emitter.removeAllListeners(name);
});
}
let tempListeners = [];

@@ -114,9 +72,9 @@

function errorListener(client, name, reject) {
let fn = function (err) {
let fn = (err) => {
if (!client.errorHandled) {
client.errorHandled = true;
if (reject) {
reject(formatError(err, name, err.code));
reject(fmtError(err, name, err.code));
} else {
throw formatError(err, name, err.code);
throw fmtError(err, name, err.code);
}

@@ -132,11 +90,11 @@ }

let fn = function () {
client.debugMsg(`Handled end event for ${name}`);
if (!client.endCalled) {
client.sftp = undefined;
if (reject) {
reject(formatError('Unexpected end event raised', name));
reject(fmtError('Unexpected end event raised', name));
} else {
throw formatError('Unexpected end event raised', name);
throw fmtError('Unexpected end event raised', name);
}
}
client.debugMsg(`Handled end event for ${name}`);
client.sftp = undefined;
};

@@ -149,11 +107,11 @@ tempListeners.push(['end', fn]);

let fn = function () {
client.debugMsg(`handled close event for ${name}`);
if (!client.endCalled) {
client.sftp = undefined;
if (reject) {
reject(formatError('Unexpected close event raised', name));
reject(fmtError('Unexpected close event raised', name));
} else {
throw formatError('Unexpected close event raised', name);
throw fmtError('Unexpected close event raised', name);
}
}
client.debugMsg(`handled close event for ${name}`);
client.sftp = undefined;
};

@@ -222,3 +180,3 @@ tempListeners.push(['close', fn]);

} catch (err) {
throw formatError(err, 'normalizeRemotePath');
throw fmtError(err, 'normalizeRemotePath');
}

@@ -239,3 +197,3 @@ }

if (!client.sftp) {
let newError = formatError(
let newError = fmtError(
'No SFTP connection available',

@@ -255,27 +213,4 @@ name,

function dumpListeners(emitter) {
let eventNames = emitter.eventNames();
if (eventNames.length) {
console.log('Listener Data');
eventNames.map((n) => {
let listeners = emitter.listeners(n);
console.log(`${n}: ${emitter.listenerCount(n)}`);
console.dir(listeners);
listeners.map((l) => {
console.log(`listener name = ${l.name}`);
});
});
}
}
function hasListener(emitter, eventName, listenerName) {
let listeners = emitter.listeners(eventName);
let matches = listeners.filter((l) => l.name == listenerName);
return matches.length === 0 ? false : true;
}
module.exports = {
formatError,
handleError,
removeListeners,
fmtError,
errorListener,

@@ -288,5 +223,3 @@ endListener,

normalizeRemotePath,
haveConnection,
dumpListeners,
hasListener
haveConnection
};

Sorry, the diff of this file is not supported yet

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc