ssh2-sftp-client 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/README.org +2 -2
- package/package.json +6 -10
- package/src/index.js +11 -4
- package/src/utils.js +17 -8
package/README.md
CHANGED
|
@@ -61,9 +61,9 @@ an SFTP client for node.js, a wrapper around [SSH2](https://github.com/mscdex/ss
|
|
|
61
61
|
|
|
62
62
|
Documentation on the methods and available options in the underlying modules can be found on the [SSH2](https://github.com/mscdex/ssh2) project pages.
|
|
63
63
|
|
|
64
|
-
Current stable release is **v7.
|
|
64
|
+
Current stable release is **v7.2.0**.
|
|
65
65
|
|
|
66
|
-
Code has been tested against Node versions
|
|
66
|
+
Code has been tested against Node versions 14.18.2, 16.13.1 and 17.2.0
|
|
67
67
|
|
|
68
68
|
Node versions < 10.x are not supported.
|
|
69
69
|
|
package/README.org
CHANGED
|
@@ -9,9 +9,9 @@ convenience abstraction as well as a Promise based API.
|
|
|
9
9
|
Documentation on the methods and available options in the underlying modules can
|
|
10
10
|
be found on the [[https://github.com/mscdex/ssh2][SSH2]] project pages.
|
|
11
11
|
|
|
12
|
-
Current stable release is *v7.
|
|
12
|
+
Current stable release is *v7.2.0*.
|
|
13
13
|
|
|
14
|
-
Code has been tested against Node versions
|
|
14
|
+
Code has been tested against Node versions 14.18.2, 16.13.1 and 17.2.0
|
|
15
15
|
|
|
16
16
|
Node versions < 10.x are not supported.
|
|
17
17
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2-sftp-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "ssh2 sftp client for node",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/theophilusx/ssh2-sftp-client"
|
|
9
9
|
},
|
|
10
|
-
"keywords": [
|
|
11
|
-
"sftp",
|
|
12
|
-
"nodejs",
|
|
13
|
-
"promises"
|
|
14
|
-
],
|
|
10
|
+
"keywords": ["sftp", "nodejs", "promises"],
|
|
15
11
|
"scripts": {
|
|
16
12
|
"test": "mocha",
|
|
17
13
|
"coverage": "nyc npm run test",
|
|
@@ -40,16 +36,16 @@
|
|
|
40
36
|
"chai-subset": "^1.6.0",
|
|
41
37
|
"checksum": "^1.0.0",
|
|
42
38
|
"dotenv": "^10.0.0",
|
|
43
|
-
"eslint": "^
|
|
39
|
+
"eslint": "^8.3.0",
|
|
44
40
|
"eslint-config-prettier": "^8.3.0",
|
|
45
41
|
"eslint-plugin-mocha": "^9.0.0",
|
|
46
42
|
"eslint-plugin-node": "^11.1.0",
|
|
47
|
-
"eslint-plugin-promise": "^5.
|
|
48
|
-
"eslint-plugin-unicorn": "^
|
|
43
|
+
"eslint-plugin-promise": "^5.2.0",
|
|
44
|
+
"eslint-plugin-unicorn": "^39.0.0",
|
|
49
45
|
"mocha": "^9.1.2",
|
|
50
46
|
"moment": "^2.29.1",
|
|
51
47
|
"nyc": "^15.1.0",
|
|
52
|
-
"prettier": "^2.
|
|
48
|
+
"prettier": "^2.5.0",
|
|
53
49
|
"through2": "^4.0.2",
|
|
54
50
|
"winston": "^3.3.3"
|
|
55
51
|
}
|
package/src/index.js
CHANGED
|
@@ -34,6 +34,7 @@ class SftpClient {
|
|
|
34
34
|
this.remotePathSep = '/';
|
|
35
35
|
this.remotePlatform = 'unix';
|
|
36
36
|
this.debug = undefined;
|
|
37
|
+
this.tempListeners = {};
|
|
37
38
|
|
|
38
39
|
this.client.on('close', () => {
|
|
39
40
|
if (this.endCalled || this.closeHandled) {
|
|
@@ -150,6 +151,7 @@ class SftpClient {
|
|
|
150
151
|
this.client.sftp((err, sftp) => {
|
|
151
152
|
if (err) {
|
|
152
153
|
this.debugMsg(`getSftpChannel: SFTP Channel Error: ${err.message}`);
|
|
154
|
+
this.client.end();
|
|
153
155
|
reject(fmtError(err, 'getSftpChannel', err.code));
|
|
154
156
|
} else {
|
|
155
157
|
this.debugMsg('getSftpChannel: SFTP channel established');
|
|
@@ -308,7 +310,7 @@ class SftpClient {
|
|
|
308
310
|
}
|
|
309
311
|
});
|
|
310
312
|
}).finally(() => {
|
|
311
|
-
removeTempListeners(this, '
|
|
313
|
+
removeTempListeners(this, '_stat');
|
|
312
314
|
});
|
|
313
315
|
};
|
|
314
316
|
|
|
@@ -549,9 +551,6 @@ class SftpClient {
|
|
|
549
551
|
* Downloads a file at remotePath to localPath using parallel reads
|
|
550
552
|
* for faster throughput.
|
|
551
553
|
*
|
|
552
|
-
* See 'fastGet' at
|
|
553
|
-
* https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md
|
|
554
|
-
*
|
|
555
554
|
* @param {String} remotePath
|
|
556
555
|
* @param {String} localPath
|
|
557
556
|
* @param {Object} options
|
|
@@ -850,6 +849,14 @@ class SftpClient {
|
|
|
850
849
|
try {
|
|
851
850
|
haveConnection(this, 'mkdir');
|
|
852
851
|
let rPath = await normalizeRemotePath(this, remotePath);
|
|
852
|
+
let targetExists = await this.exists(rPath);
|
|
853
|
+
if (targetExists && targetExists !== 'd') {
|
|
854
|
+
let error = new Error(`Bad path: ${rPath} already exists as a file`);
|
|
855
|
+
error.code = errorCode.badPath;
|
|
856
|
+
throw error;
|
|
857
|
+
} else if (targetExists) {
|
|
858
|
+
return `${rPath} already exists`;
|
|
859
|
+
}
|
|
853
860
|
if (!recursive) {
|
|
854
861
|
return await _mkdir(rPath);
|
|
855
862
|
}
|
package/src/utils.js
CHANGED
|
@@ -58,7 +58,13 @@ function fmtError(err, name = 'sftp', eCode, retryCount) {
|
|
|
58
58
|
return newError;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
function addToTempListenerList(obj, name, evt, fn) {
|
|
62
|
+
if (name in obj.tempListeners) {
|
|
63
|
+
obj.tempListeners[name].push([evt, fn]);
|
|
64
|
+
} else {
|
|
65
|
+
obj.tempListeners[name] = [[evt, fn]];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
70
|
* Simple default error listener. Will reformat the error message and
|
|
@@ -83,7 +89,7 @@ function errorListener(client, name, reject) {
|
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
};
|
|
86
|
-
|
|
92
|
+
addToTempListenerList(client, name, 'error', fn);
|
|
87
93
|
return fn;
|
|
88
94
|
}
|
|
89
95
|
|
|
@@ -104,7 +110,7 @@ function endListener(client, name, reject) {
|
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
};
|
|
107
|
-
|
|
113
|
+
addToTempListenerList(client, name, 'end', fn);
|
|
108
114
|
return fn;
|
|
109
115
|
}
|
|
110
116
|
|
|
@@ -125,7 +131,7 @@ function closeListener(client, name, reject) {
|
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
};
|
|
128
|
-
|
|
134
|
+
addToTempListenerList(client, name, 'close', fn);
|
|
129
135
|
return fn;
|
|
130
136
|
}
|
|
131
137
|
|
|
@@ -138,10 +144,12 @@ function addTempListeners(obj, name, reject) {
|
|
|
138
144
|
|
|
139
145
|
function removeTempListeners(obj, name) {
|
|
140
146
|
obj.debugMsg(`${name}: Removing temp event listeners`);
|
|
141
|
-
|
|
142
|
-
obj.
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
if (name in obj.tempListeners) {
|
|
148
|
+
obj.tempListeners[name].forEach(([e, fn]) => {
|
|
149
|
+
obj.client.removeListener(e, fn);
|
|
150
|
+
});
|
|
151
|
+
obj.tempListeners = [];
|
|
152
|
+
}
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
/**
|
|
@@ -337,6 +345,7 @@ function sleep(ms) {
|
|
|
337
345
|
|
|
338
346
|
module.exports = {
|
|
339
347
|
fmtError,
|
|
348
|
+
addToTempListenerList,
|
|
340
349
|
errorListener,
|
|
341
350
|
endListener,
|
|
342
351
|
closeListener,
|