ssh2-sftp-client 8.0.0 → 9.0.1
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 +348 -125
- package/README.org +138 -52
- package/package.json +9 -5
- package/src/constants.js +1 -0
- package/src/index.js +888 -657
- package/src/utils.js +43 -106
package/README.org
CHANGED
|
@@ -9,42 +9,59 @@ 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 *
|
|
13
|
-
|
|
14
|
-
Code has been tested against Node versions 14.19.1, 16.
|
|
15
|
-
|
|
16
|
-
Node versions <
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
12
|
+
Current stable release is *v9.0.1*.
|
|
13
|
+
|
|
14
|
+
Code has been tested against Node versions 14.19.1, 16.15.0 and 18.1.0
|
|
15
|
+
|
|
16
|
+
Node versions < 14.x are not supported.
|
|
17
|
+
|
|
18
|
+
** Version 9.x Changes
|
|
19
|
+
- *Breaking Change*: This version uses syntax not supported in node versions
|
|
20
|
+
prior to v14. Therefore, node versions less than v14 will not work.
|
|
21
|
+
- *Breaking Change*: This ~list()~ method no longer accepts a regular expression
|
|
22
|
+
for filtering the entries to be returned. You can now specify a filter
|
|
23
|
+
function instead. The function is called for each item in the list of items
|
|
24
|
+
to be returned, passing in the item object as its only argument.
|
|
25
|
+
Essentially, this is just a call to ~Array.filter()~, so the filter function
|
|
26
|
+
should behave in the same way i.e. return true for items to be retained and
|
|
27
|
+
false for those to be dropped.
|
|
28
|
+
- *Breaking Change*: The ability to set ~autoClose~ on read and write streams and
|
|
29
|
+
the ability to set ~end~ on ~pipe~ operations has been removed. These options
|
|
30
|
+
caused confusion for users and were too easy to get wrong, plus it made the
|
|
31
|
+
methods overly complicated. For those use-cases where you want to control
|
|
32
|
+
streams at a low level, two new methods have been added, ~createReadStream()~ and
|
|
33
|
+
~createWriteStream()~. However, it should be noted that client code is 100%
|
|
34
|
+
responsible for managing streams obtained using these methods. Use at your
|
|
35
|
+
own risk!
|
|
36
|
+
- *Breaking Change*: The 3rd argument to ~uploadDir()~ and ~downloadDir()~ methods
|
|
37
|
+
has been change. Previously, the argument was a filter function used to
|
|
38
|
+
select which directories and files to be transferred. The 3rd argument is
|
|
39
|
+
now an options object with two supported properties, ~filter~ and ~useFastput~
|
|
40
|
+
(for ~uploadDir()~) or ~useFastget~ (for ~downloadDir()~). If ~useFastput~ is true,
|
|
41
|
+
the ~fastPut()~ method will be pused to upload files. If ~false~ or missing, the
|
|
42
|
+
slower, but better supported, ~put()~ method will be used. Likewise, the
|
|
43
|
+
~useFastget~ options can be set to ~true~ to use the ~fastGet()~ method for
|
|
44
|
+
donwloading files, otherwise the slower, but more reliable, ~get()~ method
|
|
45
|
+
will be used.
|
|
46
|
+
- The ~uploadDir()~ and ~downloadDir()~ methods now use asynchrounous processes to
|
|
47
|
+
upload/download files. This should result in improved performance for these
|
|
48
|
+
two methods.
|
|
49
|
+
- New Methods: Two new methods, ~createWriteStream()~ and ~createReadStream()~
|
|
50
|
+
have been added. These methods will return a stream object connected to a
|
|
51
|
+
remote file on the ~sftp~ server. Client code is responsible for managing
|
|
52
|
+
these stream objects. This includes adding any necessary event listeners and
|
|
53
|
+
disposing of the objects once finished with them.
|
|
54
|
+
- Refactoring of Listeners: The library manages temporary listeners in order
|
|
55
|
+
to provide a way to catch events and processes them inside a ~Promise~
|
|
56
|
+
context. Previously, every method added its own set of temporary listeners.
|
|
57
|
+
However, this could result in multiple sets of listeners being added,
|
|
58
|
+
especially for methods which call other methods as part of their processing
|
|
59
|
+
e.g. ~rmdir(),~ ~uploadDir()~ and ~dowqnloadDir()~. To avoid this, /internal only/
|
|
60
|
+
versions of each method have been created. These internal methods use an
|
|
61
|
+
/underscore/ ~_~ prefix. Client code should not use these methods directly.
|
|
62
|
+
- New method: Added ~rcopy()~ method to perform a remote copy of a file on the remote SFTP server.
|
|
63
|
+
- Bumped ssh2 version to 1.11.0
|
|
64
|
+
|
|
48
65
|
* Installation
|
|
49
66
|
|
|
50
67
|
#+begin_src shell
|
|
@@ -250,16 +267,17 @@ for that package for an explanation of these values.
|
|
|
250
267
|
});
|
|
251
268
|
#+end_src
|
|
252
269
|
|
|
253
|
-
*** list(path,
|
|
270
|
+
*** list(path, filter) ==> Array[object]
|
|
254
271
|
|
|
255
272
|
Retrieves a directory listing. This method returns a Promise, which once
|
|
256
273
|
realised, returns an array of objects representing items in the remote
|
|
257
274
|
directory.
|
|
258
275
|
|
|
259
276
|
- path :: {String} Remote directory path
|
|
260
|
-
-
|
|
261
|
-
|
|
262
|
-
|
|
277
|
+
- filter :: (optional) {function} A function used to filter the items included
|
|
278
|
+
in the returned array. The function is called for each item with the item
|
|
279
|
+
object being passed in as the argument. The function is passed to
|
|
280
|
+
Array.filter() to perform the filtering.
|
|
263
281
|
|
|
264
282
|
**** Example Use
|
|
265
283
|
|
|
@@ -308,6 +326,7 @@ The objects in the array returned by ~list()~ have the following properties;
|
|
|
308
326
|
},
|
|
309
327
|
owner: // user ID
|
|
310
328
|
group: // group ID
|
|
329
|
+
longname: // like ls -l line
|
|
311
330
|
}
|
|
312
331
|
#+end_src
|
|
313
332
|
|
|
@@ -875,7 +894,7 @@ exists. instead, use the ~exist()~ method.
|
|
|
875
894
|
|
|
876
895
|
Returns what the server believes is the current remote working directory.
|
|
877
896
|
|
|
878
|
-
*** uploadDir(srcDir, dstDir,
|
|
897
|
+
*** uploadDir(srcDir, dstDir, options) ==> string
|
|
879
898
|
|
|
880
899
|
Upload the directory specified by ~srcDir~ to the remote directory specified by
|
|
881
900
|
~dstDir~. The ~dstDir~ will be created if necessary. Any sub directories within
|
|
@@ -890,7 +909,9 @@ the file was uploaded. The purpose of this event is to provide some way for
|
|
|
890
909
|
client code to get feedback on the upload progress. You can add your own listener
|
|
891
910
|
using the ~on()~ method.
|
|
892
911
|
|
|
893
|
-
The
|
|
912
|
+
The 3rd argument is an options object with two supported properties, ~filter~ and ~useFastput~.
|
|
913
|
+
|
|
914
|
+
The ~filter~ option is a function which will be called for each item
|
|
894
915
|
to be uploaded. The function will be called with two arguments. The first
|
|
895
916
|
argument is the full path of the item to be uploaded and the second argument is
|
|
896
917
|
a boolean, which will be true if the target path is for a directory. The filter
|
|
@@ -901,13 +922,22 @@ method. These array comprehension methods are known to be unsafe for
|
|
|
901
922
|
asynchronous functions. Therefore, only synchronous filter functions are
|
|
902
923
|
supported at this time.
|
|
903
924
|
|
|
925
|
+
The ~useFastput~ option is a boolean option. If ~true~, the method will use the
|
|
926
|
+
faster ~fastPut()~ method to upload files. Although this method is faster, it is
|
|
927
|
+
not supported by all SFTP servers. Enabling this option when unsupported by the
|
|
928
|
+
remote SFTP server will result in failures.
|
|
929
|
+
|
|
904
930
|
- srcDir :: A local file path specified as a string
|
|
905
931
|
- dstDir :: A remote file path specified as a string
|
|
906
|
-
-
|
|
932
|
+
- options :: An options object which supports two properties, ~filter~ and
|
|
933
|
+
~useFastput~. A filter predicate function which is called for each item in the
|
|
907
934
|
source path. The argument will receive two arguments. The first is the full
|
|
908
935
|
path to the item and the second is a boolean which will be true if the item is
|
|
909
936
|
a directory. If the function returns true, the item will be uploaded,
|
|
910
|
-
otherwise it will be filtered out and ignored.
|
|
937
|
+
otherwise it will be filtered out and ignored. The ~useFastput~ option is a
|
|
938
|
+
boolean option. If ~true~, the method will use the faster, but less supported,
|
|
939
|
+
~fastPut()~ method to transfer files. The default is to use the slightly slower,
|
|
940
|
+
but better supported, ~put()~ method.
|
|
911
941
|
|
|
912
942
|
**** Example
|
|
913
943
|
|
|
@@ -959,7 +989,7 @@ supported at this time.
|
|
|
959
989
|
|
|
960
990
|
#+end_src
|
|
961
991
|
|
|
962
|
-
*** downloadDir(srcDir, dstDir,
|
|
992
|
+
*** downloadDir(srcDir, dstDir, options) ==> string
|
|
963
993
|
|
|
964
994
|
Download the remote directory specified by ~srcDir~ to the local file system
|
|
965
995
|
directory specified by ~dstDir~. The ~dstDir~ directory will be created if
|
|
@@ -974,20 +1004,30 @@ the remote file that has been downloaded and the destination is the local path
|
|
|
974
1004
|
to where the file was downloaded to. You can add a listener for this event using
|
|
975
1005
|
the ~on()~ method.
|
|
976
1006
|
|
|
977
|
-
The
|
|
978
|
-
|
|
979
|
-
|
|
1007
|
+
The ~options~ argument is an options object with two supported properties, ~filter~
|
|
1008
|
+
and ~useFastget~. The ~filter~ argument is a predicate function which will be called
|
|
1009
|
+
with two arguments for each potential item to be downloaded. The first argument
|
|
1010
|
+
is the full path of the item and the second argument is a boolean, which will be
|
|
980
1011
|
true if the item is a directory. If the function returns true, the item will be
|
|
981
1012
|
included in the download. If it returns false, it will be filtered and ignored.
|
|
982
1013
|
The filter function is called via the ~Array.filter~ method. These array
|
|
983
1014
|
comprehension methods are known to be unsafe for asynchronous functions.
|
|
984
1015
|
Therefore, only synchronous filter functions are supported at this time.
|
|
985
1016
|
|
|
1017
|
+
If the ~useFastget~ property is set to ~true~, the method will use ~fastGet()~ to
|
|
1018
|
+
transfer files. The ~fastGet~ method is faster, but not supported by all SFTP
|
|
1019
|
+
services.
|
|
1020
|
+
|
|
986
1021
|
- srcDir :: A remote file path specified as a string
|
|
987
1022
|
- dstDir :: A local file path specified as a string
|
|
988
|
-
-
|
|
1023
|
+
- options :: An object with two supported properties, ~filter~ and ~useFastget~. The
|
|
1024
|
+
filter property is a function accepting two arguments, the full path to an
|
|
989
1025
|
item and a boolean value which will be true if the item is a directory. The
|
|
990
|
-
function is called for each item in the download path
|
|
1026
|
+
function is called for each item in the download path and should return true
|
|
1027
|
+
to include the item and false to exclude it in the download. The ~useFastget~
|
|
1028
|
+
property is a boolean. If true, the ~fastGet()~ method will be used to transfer
|
|
1029
|
+
files. If ~false~ (the default), the slower but better supported ~get()~ mehtod is
|
|
1030
|
+
used. .
|
|
991
1031
|
|
|
992
1032
|
**** Example
|
|
993
1033
|
|
|
@@ -1037,6 +1077,52 @@ Therefore, only synchronous filter functions are supported at this time.
|
|
|
1037
1077
|
|
|
1038
1078
|
#+end_src
|
|
1039
1079
|
|
|
1080
|
+
|
|
1081
|
+
*** createReadStream(remotePath, options)) ==> stream object
|
|
1082
|
+
|
|
1083
|
+
Returns a read stream object which is attached to the remote file specified by
|
|
1084
|
+
the ~remotePath~ argument. This is a low level method which just returns a read
|
|
1085
|
+
stream object. Client code is fully responsible for managing and releasing the
|
|
1086
|
+
resources associated with the stream once finished i.e. closing files,
|
|
1087
|
+
removing listeners etc.
|
|
1088
|
+
|
|
1089
|
+
- remotePath :: A remote file path specified as a string
|
|
1090
|
+
- options :: An options object. Supported properties are
|
|
1091
|
+
- flags :: defaults to 'r'
|
|
1092
|
+
- encoding :: defaults to null
|
|
1093
|
+
- handle :: defaults to null
|
|
1094
|
+
- mode :: 0o666
|
|
1095
|
+
- autoClose :: defaults to true. If set to false, client code is responsible
|
|
1096
|
+
for closing file descriptors when finished
|
|
1097
|
+
- start :: Default 0. Position to start reading bytes from (inclusive)
|
|
1098
|
+
- end :: Postion to stop reading bytes (inclusive).
|
|
1099
|
+
|
|
1100
|
+
*** createWriteStream(remotePath, options) ==> stream object
|
|
1101
|
+
|
|
1102
|
+
Returns a write stream object which is attached to the remote file specified
|
|
1103
|
+
in the ~remotePath~ argument. This is a low legvel function which just returns
|
|
1104
|
+
the stream object. Client code is fully responsible for managing that object,
|
|
1105
|
+
including closing any file descriptiors and removing listeners etc.
|
|
1106
|
+
|
|
1107
|
+
- remotePath :: Path to the remote file specified as a string
|
|
1108
|
+
- options :: An object containing stream options. Supported properties include
|
|
1109
|
+
- flags :: default 'w'
|
|
1110
|
+
- encoding :: defulat null
|
|
1111
|
+
- mode :: 0o666
|
|
1112
|
+
- autoClose :: true
|
|
1113
|
+
- start :: Byte position to start writing from (inclusive). May require
|
|
1114
|
+
changing flag to 'r+'.
|
|
1115
|
+
|
|
1116
|
+
*** rcopy(srcPath, dstPath) ==> string
|
|
1117
|
+
|
|
1118
|
+
Perfrom a remote file copy. The file identified by the ~srcPath~ argument will
|
|
1119
|
+
be copied to the file specified as the ~dstPath~ argument. The directory where
|
|
1120
|
+
~dstPath~ will be placed must exist, but the actual file must not i.e. no
|
|
1121
|
+
overwrites allowed.
|
|
1122
|
+
|
|
1123
|
+
- srcPath :: Path to remote file to be copied specified as a string
|
|
1124
|
+
- dstPath :: Path to where the copy will be creaeted specified as a string
|
|
1125
|
+
|
|
1040
1126
|
*** end() ==> boolean
|
|
1041
1127
|
|
|
1042
1128
|
Ends the current client session, releasing the client socket and associated
|
|
@@ -1353,7 +1439,7 @@ This solution was provided by @jmorino.
|
|
|
1353
1439
|
const port = 22; // default SSH/SFTP port on remote server
|
|
1354
1440
|
|
|
1355
1441
|
// connect to SOCKS 5 proxy
|
|
1356
|
-
const {
|
|
1442
|
+
const { socks } = await SocksClient.createConnection({
|
|
1357
1443
|
proxy: {
|
|
1358
1444
|
host: 'my.proxy', // proxy hostname
|
|
1359
1445
|
port: 1080, // proxy port
|
|
@@ -1366,7 +1452,7 @@ This solution was provided by @jmorino.
|
|
|
1366
1452
|
const client = new SFTPClient();
|
|
1367
1453
|
client.connect({
|
|
1368
1454
|
host,
|
|
1369
|
-
sock: socket, // pass the socket to proxy here (see ssh2 doc)
|
|
1455
|
+
sock: socks.socket, // pass the socket to proxy here (see ssh2 doc)
|
|
1370
1456
|
username: '.....',
|
|
1371
1457
|
privateKey: '.....'
|
|
1372
1458
|
})
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2-sftp-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.1",
|
|
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": [
|
|
10
|
+
"keywords": [
|
|
11
|
+
"sftp",
|
|
12
|
+
"nodejs",
|
|
13
|
+
"promises"
|
|
14
|
+
],
|
|
11
15
|
"scripts": {
|
|
12
16
|
"test": "mocha",
|
|
13
17
|
"coverage": "nyc npm run test",
|
|
@@ -31,13 +35,13 @@
|
|
|
31
35
|
"chai-subset": "^1.6.0",
|
|
32
36
|
"checksum": "^1.0.0",
|
|
33
37
|
"dotenv": "^16.0.0",
|
|
34
|
-
"eslint": "^8.
|
|
38
|
+
"eslint": "^8.17.0",
|
|
35
39
|
"eslint-config-prettier": "^8.5.0",
|
|
36
40
|
"eslint-plugin-mocha": "^10.0.3",
|
|
37
41
|
"eslint-plugin-node": "^11.1.0",
|
|
38
42
|
"eslint-plugin-promise": "^6.0.0",
|
|
39
43
|
"eslint-plugin-unicorn": "^42.0.0",
|
|
40
|
-
"mocha": "^
|
|
44
|
+
"mocha": "^10.0.0",
|
|
41
45
|
"moment": "^2.29.1",
|
|
42
46
|
"nyc": "^15.1.0",
|
|
43
47
|
"prettier": "^2.6.1",
|
|
@@ -47,6 +51,6 @@
|
|
|
47
51
|
"dependencies": {
|
|
48
52
|
"concat-stream": "^2.0.0",
|
|
49
53
|
"promise-retry": "^2.0.1",
|
|
50
|
-
"ssh2": "^1.
|
|
54
|
+
"ssh2": "^1.11.0"
|
|
51
55
|
}
|
|
52
56
|
}
|