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

ssh2-sftp-client

Package Overview
Dependencies
Maintainers
2
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 4.2.0 to 4.2.1

5

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

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

"sftp",
"nodejs"
"nodejs",
"promises"
],

@@ -15,0 +16,0 @@ "scripts": {

237

README.md
# Table of Contents
1. [SSH2 SFTP Client](#org2d4beb0)
2. [Installation](#org1b2885a)
3. [Basic Usage](#org225126f)
4. [Breaking Changes in Version 4.x](#org2cf43bd)
5. [Enhancements in Version 4.2.x](#org30c96ac)
6. [Enhancements in Version 4.1.x](#org5777d99)
7. [Documentation](#org8c25b6e)
1. [Methods](#org8f330c9)
1. [new SftpClient(name) ===> SFTP client object](#orgb660d8f)
2. [connect(config) ===> SFTPstream](#org1a60cfb)
3. [list(path, pattern) ==> Array[object]](#org8a1dff4)
4. [exists(path) ==> boolean](#orgaa778db)
5. [stat(path) ==> object](#org5184595)
6. [get(path, dst, options) ==> String|Stream|Buffer](#orga0dfcd5)
7. [fastGet(remotePath, localPath, options) ===> string](#org1f07b2e)
8. [put(src, remotePath, options) ==> string](#org372e9a1)
9. [fastPut(localPath, remotePath, options) ==> string](#org6c596b7)
10. [append(input, remotePath, options) ==> string](#orgfdb9a8f)
11. [mkdir(path, recursive) ==> string](#orgd57aded)
12. [rmdir(path, recursive) ==> string](#orgdb74ea9)
13. [delete(path) ==> string](#orga755e94)
14. [rename(fromPath, toPath) ==> string](#org74fb8ca)
15. [chmod(path, mode) ==> string](#orgf44a17a)
16. [realPath(path) ===> string](#orge8bc11c)
17. [cwd() ==> string](#orgc9d3058)
18. [end() ==> boolean](#org72b3f6f)
19. [Add and Remove Listeners](#orge7b5b8a)
8. [FAQ](#org06ab353)
1. [Remote server drops connections with only an end event](#org5bac919)
2. [How can you pass writable stream as dst for get method?](#org5e6420c)
3. [How can I upload files without having to specify a password?](#org6ec13f2)
4. [How can I connect through a Socks Proxy](#org5501a07)
9. [Change Log](#orgf32a1e7)
1. [v4.2.0 (Prod Version)](#org8f7647b)
2. [v4.1.0](#org790e255)
3. [v4.0.4](#orgbc6936f)
4. [v4.0.3](#orga5291fb)
5. [v4.0.2](#orgbf82349)
6. [v4.0.0](#org9d05647)
7. [v2.5.2](#orgee92c3b)
8. [v2.5.1](#orgca044c2)
9. [v2.5.0](#orgfd95552)
10. [v2.4.3](#orge8df065)
11. [v2.4.2](#org1c6d986)
12. [v2.4.1](#orgc755940)
13. [v2.4.0](#orgc29393a)
14. [v2.3.0](#orgd43c13b)
15. [v3.0.0 – deprecate this version](#orgc15e6ab)
16. [v2.1.1](#org3d8c204)
17. [v2.0.1](#org186bc44)
18. [v1.1.0](#orgeec7323)
19. [v1.0.5:](#org54b2653)
10. [Logging Issues](#org8c07de1)
11. [Pull Requests](#orge0fc98c)
12. [Contributors](#org3d70747)
1. [SSH2 SFTP Client](#org2ff92dd)
2. [Installation](#org101da24)
3. [Basic Usage](#orge0baaf0)
4. [Breaking Changes in Version 4.x](#org1450b73)
5. [Enhancements in Version 4.2.x](#org0da6002)
6. [Enhancements in Version 4.1.x](#org436dffc)
7. [Documentation](#org627f927)
1. [Methods](#org2e64c16)
1. [new SftpClient(name) ===> SFTP client object](#orga990762)
2. [connect(config) ===> SFTPstream](#orga24c78c)
3. [list(path, pattern) ==> Array[object]](#org62856bf)
4. [exists(path) ==> boolean](#orgf1725d7)
5. [stat(path) ==> object](#orgca82db5)
6. [get(path, dst, options) ==> String|Stream|Buffer](#orgf03d9dc)
7. [fastGet(remotePath, localPath, options) ===> string](#org60015f8)
8. [put(src, remotePath, options) ==> string](#org4c453c1)
9. [fastPut(localPath, remotePath, options) ==> string](#org43ba146)
10. [append(input, remotePath, options) ==> string](#orgeb14ec0)
11. [mkdir(path, recursive) ==> string](#orge36efb6)
12. [rmdir(path, recursive) ==> string](#org4e9756a)
13. [delete(path) ==> string](#org5558876)
14. [rename(fromPath, toPath) ==> string](#org8d1ae7f)
15. [chmod(path, mode) ==> string](#orgd6f506d)
16. [realPath(path) ===> string](#orge278e16)
17. [cwd() ==> string](#org03d8066)
18. [end() ==> boolean](#org48ede29)
19. [Add and Remove Listeners](#orgdb4973a)
8. [FAQ](#orgd9bd9d8)
1. [Remote server drops connections with only an end event](#org5abb622)
2. [How can you pass writable stream as dst for get method?](#org3e21a0f)
3. [How can I upload files without having to specify a password?](#orgad53a21)
4. [How can I connect through a Socks Proxy](#org89b487a)
9. [Change Log](#org74bc7f8)
1. [v4.2.1 (Prod Version)](#org135b786)
2. [v4.2.0](#orgec101e3)
3. [v4.1.0](#org5da0e74)
4. [v4.0.4](#org8266de9)
5. [v4.0.3](#orgef2b0c4)
6. [v4.0.2](#org9e36bec)
7. [v4.0.0](#orge515716)
8. [v2.5.2](#org453ef69)
9. [v2.5.1](#org929e671)
10. [v2.5.0](#org09654d5)
11. [v2.4.3](#orgc17457a)
12. [v2.4.2](#org3708b37)
13. [v2.4.1](#org5293271)
14. [v2.4.0](#orgaea5aba)
15. [v2.3.0](#org65eab1d)
16. [v3.0.0 – deprecate this version](#orgcb65936)
17. [v2.1.1](#org5324914)
18. [v2.0.1](#org7238a3b)
19. [v1.1.0](#org026a96e)
20. [v1.0.5:](#org0e31491)
10. [Logging Issues](#org4860a8f)
11. [Pull Requests](#orgffb1857)
12. [Contributors](#org891dcee)
<a id="org2d4beb0"></a>
<a id="org2ff92dd"></a>

@@ -78,3 +79,3 @@ # SSH2 SFTP Client

<a id="org1b2885a"></a>
<a id="org101da24"></a>

@@ -86,3 +87,3 @@ # Installation

<a id="org225126f"></a>
<a id="orge0baaf0"></a>

@@ -108,3 +109,3 @@ # Basic Usage

<a id="org2cf43bd"></a>
<a id="org1450b73"></a>

@@ -137,3 +138,3 @@ # Breaking Changes in Version 4.x

<a id="org30c96ac"></a>
<a id="org0da6002"></a>

@@ -157,3 +158,3 @@ # Enhancements in Version 4.2.x

<a id="org5777d99"></a>
<a id="org436dffc"></a>

@@ -171,3 +172,3 @@ # Enhancements in Version 4.1.x

<a id="org8c25b6e"></a>
<a id="org627f927"></a>

@@ -183,3 +184,3 @@ # Documentation

<a id="org8f330c9"></a>
<a id="org2e64c16"></a>

@@ -189,3 +190,3 @@ ## Methods

<a id="orgb660d8f"></a>
<a id="orga990762"></a>

@@ -229,3 +230,3 @@ ### new SftpClient(name) ===> SFTP client object

<a id="org1a60cfb"></a>
<a id="orga24c78c"></a>

@@ -300,3 +301,3 @@ ### connect(config) ===> SFTPstream

<a id="org8a1dff4"></a>
<a id="org62856bf"></a>

@@ -374,3 +375,3 @@ ### list(path, pattern) ==> Array[object]

<a id="orgaa778db"></a>
<a id="orgf1725d7"></a>

@@ -410,3 +411,3 @@ ### exists(path) ==> boolean

<a id="org5184595"></a>
<a id="orgca82db5"></a>

@@ -458,3 +459,3 @@ ### stat(path) ==> object

<a id="orga0dfcd5"></a>
<a id="orgf03d9dc"></a>

@@ -519,3 +520,3 @@ ### get(path, dst, options) ==> String|Stream|Buffer

<a id="org1f07b2e"></a>
<a id="org60015f8"></a>

@@ -563,3 +564,3 @@ ### fastGet(remotePath, localPath, options) ===> string

<a id="org372e9a1"></a>
<a id="org4c453c1"></a>

@@ -617,3 +618,3 @@ ### put(src, remotePath, options) ==> string

<a id="org6c596b7"></a>
<a id="org43ba146"></a>

@@ -661,3 +662,3 @@ ### fastPut(localPath, remotePath, options) ==> string

<a id="orgfdb9a8f"></a>
<a id="orgeb14ec0"></a>

@@ -707,3 +708,3 @@ ### append(input, remotePath, options) ==> string

<a id="orgd57aded"></a>
<a id="orge36efb6"></a>

@@ -737,3 +738,3 @@ ### mkdir(path, recursive) ==> string

<a id="orgdb74ea9"></a>
<a id="org4e9756a"></a>

@@ -768,3 +769,3 @@ ### rmdir(path, recursive) ==> string

<a id="orga755e94"></a>
<a id="org5558876"></a>

@@ -794,3 +795,3 @@ ### delete(path) ==> string

<a id="org74fb8ca"></a>
<a id="org8d1ae7f"></a>

@@ -820,3 +821,3 @@ ### rename(fromPath, toPath) ==> string

<a id="orgf44a17a"></a>
<a id="orgd6f506d"></a>

@@ -849,3 +850,3 @@ ### chmod(path, mode) ==> string

<a id="orge8bc11c"></a>
<a id="orge278e16"></a>

@@ -860,3 +861,3 @@ ### realPath(path) ===> string

<a id="orgc9d3058"></a>
<a id="org03d8066"></a>

@@ -868,3 +869,3 @@ ### cwd() ==> string

<a id="org72b3f6f"></a>
<a id="org48ede29"></a>

@@ -892,3 +893,3 @@ ### end() ==> boolean

<a id="orge7b5b8a"></a>
<a id="orgdb4973a"></a>

@@ -919,3 +920,3 @@ ### Add and Remove Listeners

<a id="org06ab353"></a>
<a id="orgd9bd9d8"></a>

@@ -925,3 +926,3 @@ # FAQ

<a id="org5bac919"></a>
<a id="org5abb622"></a>

@@ -956,3 +957,3 @@ ## Remote server drops connections with only an end event

<a id="org5e6420c"></a>
<a id="org3e21a0f"></a>

@@ -1021,3 +1022,3 @@ ## How can you pass writable stream as dst for get method?

<a id="org6ec13f2"></a>
<a id="orgad53a21"></a>

@@ -1057,3 +1058,3 @@ ## How can I upload files without having to specify a password?

<a id="org5501a07"></a>
<a id="org89b487a"></a>

@@ -1093,3 +1094,3 @@ ## How can I connect through a Socks Proxy

<a id="orgf32a1e7"></a>
<a id="org74bc7f8"></a>

@@ -1099,6 +1100,20 @@ # Change Log

<a id="org8f7647b"></a>
<a id="org135b786"></a>
## v4.2.0 (Prod Version)
## v4.2.1 (Prod Version)
- Remove default close listener. changes in ssh2 API removed the utility of a
default close listener
- Fix path handling. Under mixed environments (where client platform and
server platform were different i.e. one windows the other unix), path
handling was broken due tot he use of path.join().
- Ensure error messages include path details. Instead of errors such as "No
such file" now report "No such file /path/to/missing/file" to help with
debugging
<a id="orgec101e3"></a>
## v4.2.0
- Work-around for SSH2 `end` event bug

@@ -1111,3 +1126,3 @@ - Added ability to set client name in constructor method

<a id="org790e255"></a>
<a id="org5da0e74"></a>

@@ -1129,3 +1144,3 @@ ## v4.1.0

<a id="orgbc6936f"></a>
<a id="org8266de9"></a>

@@ -1138,3 +1153,3 @@ ## v4.0.4

<a id="orga5291fb"></a>
<a id="orgef2b0c4"></a>

@@ -1147,3 +1162,3 @@ ## v4.0.3

<a id="orgbf82349"></a>
<a id="org9e36bec"></a>

@@ -1155,3 +1170,3 @@ ## v4.0.2

<a id="org9d05647"></a>
<a id="orge515716"></a>

@@ -1174,3 +1189,3 @@ ## v4.0.0

<a id="orgee92c3b"></a>
<a id="org453ef69"></a>

@@ -1183,3 +1198,3 @@ ## v2.5.2

<a id="orgca044c2"></a>
<a id="org929e671"></a>

@@ -1191,3 +1206,3 @@ ## v2.5.1

<a id="orgfd95552"></a>
<a id="org09654d5"></a>

@@ -1199,3 +1214,3 @@ ## v2.5.0

<a id="orge8df065"></a>
<a id="orgc17457a"></a>

@@ -1208,3 +1223,3 @@ ## v2.4.3

<a id="org1c6d986"></a>
<a id="org3708b37"></a>

@@ -1217,3 +1232,3 @@ ## v2.4.2

<a id="orgc755940"></a>
<a id="org5293271"></a>

@@ -1226,3 +1241,3 @@ ## v2.4.1

<a id="orgc29393a"></a>
<a id="orgaea5aba"></a>

@@ -1240,3 +1255,3 @@ ## v2.4.0

<a id="orgd43c13b"></a>
<a id="org65eab1d"></a>

@@ -1250,3 +1265,3 @@ ## v2.3.0

<a id="orgc15e6ab"></a>
<a id="orgcb65936"></a>

@@ -1259,3 +1274,3 @@ ## v3.0.0 &#x2013; deprecate this version

<a id="org3d8c204"></a>
<a id="org5324914"></a>

@@ -1268,3 +1283,3 @@ ## v2.1.1

<a id="org186bc44"></a>
<a id="org7238a3b"></a>

@@ -1279,3 +1294,3 @@ ## v2.0.1

<a id="orgeec7323"></a>
<a id="org026a96e"></a>

@@ -1287,3 +1302,3 @@ ## v1.1.0

<a id="org54b2653"></a>
<a id="org0e31491"></a>

@@ -1296,3 +1311,3 @@ ## v1.0.5:

<a id="org8c07de1"></a>
<a id="org4860a8f"></a>

@@ -1306,3 +1321,3 @@ # Logging Issues

<a id="orge0fc98c"></a>
<a id="orgffb1857"></a>

@@ -1327,3 +1342,3 @@ # Pull Requests

<a id="org3d70747"></a>
<a id="org891dcee"></a>

@@ -1330,0 +1345,0 @@ # Contributors

@@ -11,3 +11,3 @@ /**

const retry = require('retry');
const {join, posix, normalize} = require('path');
const {posix, normalize} = require('path');

@@ -18,2 +18,4 @@ let SftpClient = function(clientName = '') {

this.endCalled = false;
this.remotePathSep = '/';
this.remotePlatform = 'unix';
};

@@ -58,3 +60,3 @@

if (retryCount) {
msg += ` after ${retryCount} attempts`;
msg += ` after ${retryCount} ${retryCount > 1 ? 'attempts' : 'attempt'}`;
}

@@ -104,12 +106,11 @@ return new Error(msg);

if (!sftp) {
return reject(
formatError('No SFTP connection available', 'sftp.realPath')
);
reject(formatError('No SFTP connection available', 'sftp.realPath'));
} else {
sftp.realpath(path, (err, absPath) => {
if (err) {
reject(formatError(`${err.message} ${path}`, 'sftp.realPath'));
}
resolve(absPath);
});
}
sftp.realpath(path, (err, absPath) => {
if (err) {
reject(formatError(`${err.message} ${path}`, 'sftp.realPath'));
}
resolve(absPath);
});
} catch (err) {

@@ -134,3 +135,3 @@ reject(formatError(`${err.message} ${path}`, 'sftp.realPath'));

if (err) {
reject(formatError(err, 'sftp.list'));
reject(formatError(`${err.message} ${path}`, 'sftp.list'));
} else {

@@ -262,3 +263,3 @@ let newList = [];

if (err) {
reject(formatError(err, 'sftp.stat'));
reject(formatError(`${err.message} ${remotePath}`, 'sftp.stat'));
} else {

@@ -306,3 +307,3 @@ resolve({

removeListeners(rdr);
reject(formatError(err, 'sftp.get'));
reject(formatError(`${err.message} ${path}`, 'sftp.get'));
});

@@ -328,3 +329,8 @@

removeListeners(rdr);
reject(formatError(err, 'sftp.get'));
reject(
formatError(
`${err.message} ${typeof dst === 'string' ? dst : ''}`,
'sftp.get'
)
);
});

@@ -383,3 +389,3 @@ wtr.on('finish', () => {

if (err) {
reject(formatError(err, 'sftp.fastGet'));
reject(formatError(`${err.message} ${remotePath}`, 'sftp.fastGet'));
}

@@ -418,3 +424,8 @@ resolve(`${remotePath} was successfully download to ${localPath}!`);

if (err) {
reject(formatError(err, 'sftp.fastPut'));
reject(
formatError(
`${err.message} Local: ${localPath} Remote: ${remotePath}`,
'sftp.fastPut'
)
);
}

@@ -445,8 +456,8 @@ resolve(`${localPath} was successfully uploaded to ${remotePath}!`);

let dst = remotePath;
if (dst.startsWith('../')) {
if (dst.startsWith('..')) {
let root = await this.realPath('..');
dst = join(root, dst.substring(3));
} else if (dst.startsWith('./')) {
dst = root + this.remotePathSep + dst.substring(3);
} else if (dst.startsWith('.')) {
let root = await this.realPath('.');
dst = join(root, dst.substring(2));
dst = root + this.remotePathSep + dst.substring(2);
}

@@ -463,3 +474,3 @@ return this._fastPut(src, dst, options);

stream.on('error', err => {
reject(formatError(err, 'sftp.put'));
reject(formatError(`${err.message} ${remotePath}`, 'sftp.put'));
});

@@ -483,3 +494,8 @@

removeListeners(stream);
reject(formatError(err, 'sftp.put'));
reject(
formatError(
`${err.message} ${typeof src === 'string' ? src : ''}`,
'sftp.put'
)
);
});

@@ -512,8 +528,8 @@ rdr.pipe(stream);

let dst = remotePath;
if (dst.startsWith('../')) {
if (dst.startsWith('..')) {
let root = await this.realPath('..');
dst = join(root, dst.substring(3));
} else if (dst.startsWith('./')) {
dst = root + this.remotePathSep + dst.substring(3);
} else if (dst.startsWith('.')) {
let root = await this.realPath('.');
dst = join(root, dst.substring(2));
dst = root + this.remotePathSep + dst.substring(2);
}

@@ -542,3 +558,3 @@ return this._put(src, dst, options);

removeListeners(stream);
reject(formatError(err, 'sftp.append'));
reject(formatError(`${err.message} ${remotePath}`, 'sftp.append'));
});

@@ -604,3 +620,3 @@

if (err) {
reject(formatError('Failed to create directory', 'sftp.mkdir'));
reject(formatError(`${err.message} ${p}`, 'sftp.mkdir'));
}

@@ -617,8 +633,8 @@ resolve(`${p} directory created`);

let realPath = path;
if (realPath.startsWith('../')) {
if (realPath.startsWith('..')) {
let root = await this.realPath('..');
realPath = join(root, realPath.substring(3));
} else if (realPath.startsWith('./')) {
realPath = root + this.remotePathSep + realPath.substring(3);
} else if (realPath.startsWith('.')) {
let root = await this.realPath('.');
realPath = join(root, realPath.substring(2));
realPath = root + this.remotePathSep + realPath.substring(2);
}

@@ -661,3 +677,3 @@

if (err) {
reject(formatError(err, 'sftp.rmdir'));
reject(formatError(`${err.message} ${p}`, 'sftp.rmdir'));
}

@@ -686,3 +702,3 @@ resolve('Successfully removed directory');

try {
await this.delete(join(absPath, f.name));
await this.delete(absPath + this.remotePathSep + f.name);
} catch (err) {

@@ -694,3 +710,3 @@ throw formatError(err, 'sftp.rmdir');

try {
await this.rmdir(join(absPath, d.name), true);
await this.rmdir(absPath + this.remotePathSep + d.name, true);
} catch (err) {

@@ -713,3 +729,3 @@ throw formatError(err, 'sftp.rmdir');

if (err) {
reject(formatError(err, 'sftp.delete'));
reject(formatError(`${err.message} ${path}`, 'sftp.delete'));
}

@@ -744,3 +760,8 @@ resolve('Successfully deleted file');

if (err) {
reject(formatError(err, 'sftp.rename'));
reject(
formatError(
`${err.message} From: ${fromPath} To: ${toPath}`,
'sftp.rename'
)
);
}

@@ -769,8 +790,8 @@ resolve(`Successfully renamed ${fromPath} to ${toPath}`);

let dst = toPath;
if (dst.startsWith('../')) {
if (dst.startsWith('..')) {
let root = await this.realPath('..');
dst = join(root, dst.substring(3));
} else if (dst.startsWith('./')) {
dst = root + this.remotePathSep + dst.substring(3);
} else if (dst.startsWith('.')) {
let root = await this.realPath('.');
dst = join(root, dst.substring(2));
dst = root + this.remotePathSep + dst.substring(2);
}

@@ -786,3 +807,3 @@ return this._rename(src, dst);

if (err) {
reject(formatError(err, 'sftp.chmod'));
reject(formatError(`${err.message} ${remotePath}`, 'sftp.chmod'));
}

@@ -853,7 +874,2 @@ resolve('Successfully change file mode');

self.client.on('error', makeErrorListener(self.clientName));
self.client.on('close', withError => {
if (withError) {
console.error('Client ended due to errors');
}
});
callback(null, sftp);

@@ -880,3 +896,2 @@ });

})
.connect(config);

@@ -902,4 +917,23 @@ });

reject(err);
} else {
sftp.realpath('.', (err, absPath) => {
if (err) {
reject(
formatError(
`Failed to determine remote server type: ${err.message}`,
'sftp.connect'
)
);
} else {
if (absPath.startsWith('/')) {
self.remotePathSep = '/';
self.remotePlatform = 'unix';
} else {
self.remotePathSep = '\\';
self.remotePlatform = 'windows';
}
resolve(sftp);
}
});
}
resolve(sftp);
});

@@ -923,3 +957,3 @@ }

*
* Close the SFTP connection
* End the SFTP connection
*

@@ -934,6 +968,2 @@ */

// debugListeners(this.client);
// obj.client.on('close', () => {
// removeListeners(obj.client);
// //resolve(true);
// });
self.client.end();

@@ -940,0 +970,0 @@ removeListeners(self.client);

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