ssh2-sftp-client 8.1.0 → 9.0.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/.dir-local.el +1 -0
- package/README.md +182 -130
- package/README.org +129 -52
- package/package.json +4 -4
- package/src/constants.js +1 -0
- package/src/index.js +875 -661
- package/src/utils.js +43 -106
package/README.org
CHANGED
|
@@ -9,7 +9,7 @@ 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 *
|
|
12
|
+
Current stable release is *v9.0.0*.
|
|
13
13
|
|
|
14
14
|
Code has been tested against Node versions 14.19.1, 16.15.0 and 18.1.0
|
|
15
15
|
|
|
@@ -17,43 +17,52 @@ Node versions < 12.x are not supported. However, node v10.x should still work,
|
|
|
17
17
|
although some tests will fail due to changes in file system functions used in
|
|
18
18
|
test setup and tear down.
|
|
19
19
|
|
|
20
|
-
** Version
|
|
21
|
-
|
|
22
|
-
- *Breaking Change*:
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
20
|
+
** Version 9.x Changes
|
|
21
|
+
|
|
22
|
+
- *Breaking Change*: This ~list()~ method no longer accepts a regular expression
|
|
23
|
+
for filtering the entries to be returned. You can now specify a filter
|
|
24
|
+
function instead. The function is called for each item in the list of items
|
|
25
|
+
to be returned, passing in the item object as its only argument.
|
|
26
|
+
Essentially, this is just a call to ~Array.filter()~, so the filter function
|
|
27
|
+
should behave in the same way i.e. return true for items to be retained and
|
|
28
|
+
false for those to be dropped.
|
|
29
|
+
- *Breaking Change*: The ability to set ~autoClose~ on read and write streams and
|
|
30
|
+
the ability to set ~end~ on ~pipe~ operations has been removed. These options
|
|
31
|
+
caused confusion for users and were too easy to get wrong, plus it made the
|
|
32
|
+
methods overly complicated. For those use-cases where you want to control
|
|
33
|
+
streams at a low level, two new methods have been added, ~createReadStream()~ and
|
|
34
|
+
~createWriteStream()~. However, it should be noted that client code is 100%
|
|
35
|
+
responsible for managing streams obtained using these methods. Use at your
|
|
36
|
+
own risk!
|
|
37
|
+
- *Breaking Change*: The 3rd argument to ~uploadDir()~ and ~downloadDir()~ methods
|
|
38
|
+
has been change. Previously, the argument was a filter function used to
|
|
39
|
+
select which directories and files to be transferred. The 3rd argument is
|
|
40
|
+
now an options object with two supported properties, ~filter~ and ~useFastput~
|
|
41
|
+
(for ~uploadDir()~) or ~useFastget~ (for ~downloadDir()~). If ~useFastput~ is true,
|
|
42
|
+
the ~fastPut()~ method will be pused to upload files. If ~false~ or missing, the
|
|
43
|
+
slower, but better supported, ~put()~ method will be used. Likewise, the
|
|
44
|
+
~useFastget~ options can be set to ~true~ to use the ~fastGet()~ method for
|
|
45
|
+
donwloading files, otherwise the slower, but more reliable, ~get()~ method
|
|
46
|
+
will be used.
|
|
47
|
+
- The ~uploadDir()~ and ~downloadDir()~ methods now use asynchrounous processes to
|
|
48
|
+
upload/download files. This should result in improved performance for these
|
|
49
|
+
two methods.
|
|
50
|
+
- New Methods: Two new methods, ~createWriteStream()~ and ~createReadStream()~
|
|
51
|
+
have been added. These methods will return a stream object connected to a
|
|
52
|
+
remote file on the ~sftp~ server. Client code is responsible for managing
|
|
53
|
+
these stream objects. This includes adding any necessary event listeners and
|
|
54
|
+
disposing of the objects once finished with them.
|
|
55
|
+
- Refactoring of Listeners: The library manages temporary listeners in order
|
|
56
|
+
to provide a way to catch events and processes them inside a ~Promise~
|
|
57
|
+
context. Previously, every method added its own set of temporary listeners.
|
|
58
|
+
However, this could result in multiple sets of listeners being added,
|
|
59
|
+
especially for methods which call other methods as part of their processing
|
|
60
|
+
e.g. ~rmdir(),~ ~uploadDir()~ and ~dowqnloadDir()~. To avoid this, /internal only/
|
|
61
|
+
versions of each method have been created. These internal methods use an
|
|
62
|
+
/underscore/ ~_~ prefix. Client code should not use these methods directly.
|
|
63
|
+
- New method: Added ~rcopy()~ method to perform a remote copy of a file on the remote SFTP server.
|
|
64
|
+
- Bumped ssh2 version to 1.11.0
|
|
65
|
+
|
|
57
66
|
* Installation
|
|
58
67
|
|
|
59
68
|
#+begin_src shell
|
|
@@ -259,16 +268,17 @@ for that package for an explanation of these values.
|
|
|
259
268
|
});
|
|
260
269
|
#+end_src
|
|
261
270
|
|
|
262
|
-
*** list(path,
|
|
271
|
+
*** list(path, filter) ==> Array[object]
|
|
263
272
|
|
|
264
273
|
Retrieves a directory listing. This method returns a Promise, which once
|
|
265
274
|
realised, returns an array of objects representing items in the remote
|
|
266
275
|
directory.
|
|
267
276
|
|
|
268
277
|
- path :: {String} Remote directory path
|
|
269
|
-
-
|
|
270
|
-
|
|
271
|
-
|
|
278
|
+
- filter :: (optional) {function} A function used to filter the items included
|
|
279
|
+
in the returned array. The function is called for each item with the item
|
|
280
|
+
object being passed in as the argument. The function is passed to
|
|
281
|
+
Array.filter() to perform the filtering.
|
|
272
282
|
|
|
273
283
|
**** Example Use
|
|
274
284
|
|
|
@@ -885,7 +895,7 @@ exists. instead, use the ~exist()~ method.
|
|
|
885
895
|
|
|
886
896
|
Returns what the server believes is the current remote working directory.
|
|
887
897
|
|
|
888
|
-
*** uploadDir(srcDir, dstDir,
|
|
898
|
+
*** uploadDir(srcDir, dstDir, options) ==> string
|
|
889
899
|
|
|
890
900
|
Upload the directory specified by ~srcDir~ to the remote directory specified by
|
|
891
901
|
~dstDir~. The ~dstDir~ will be created if necessary. Any sub directories within
|
|
@@ -900,7 +910,9 @@ the file was uploaded. The purpose of this event is to provide some way for
|
|
|
900
910
|
client code to get feedback on the upload progress. You can add your own listener
|
|
901
911
|
using the ~on()~ method.
|
|
902
912
|
|
|
903
|
-
The
|
|
913
|
+
The 3rd argument is an options object with two supported properties, ~filter~ and ~useFastput~.
|
|
914
|
+
|
|
915
|
+
The ~filter~ option is a function which will be called for each item
|
|
904
916
|
to be uploaded. The function will be called with two arguments. The first
|
|
905
917
|
argument is the full path of the item to be uploaded and the second argument is
|
|
906
918
|
a boolean, which will be true if the target path is for a directory. The filter
|
|
@@ -911,13 +923,22 @@ method. These array comprehension methods are known to be unsafe for
|
|
|
911
923
|
asynchronous functions. Therefore, only synchronous filter functions are
|
|
912
924
|
supported at this time.
|
|
913
925
|
|
|
926
|
+
The ~useFastput~ option is a boolean option. If ~true~, the method will use the
|
|
927
|
+
faster ~fastPut()~ method to upload files. Although this method is faster, it is
|
|
928
|
+
not supported by all SFTP servers. Enabling this option when unsupported by the
|
|
929
|
+
remote SFTP server will result in failures.
|
|
930
|
+
|
|
914
931
|
- srcDir :: A local file path specified as a string
|
|
915
932
|
- dstDir :: A remote file path specified as a string
|
|
916
|
-
-
|
|
933
|
+
- options :: An options object which supports two properties, ~filter~ and
|
|
934
|
+
~useFastput~. A filter predicate function which is called for each item in the
|
|
917
935
|
source path. The argument will receive two arguments. The first is the full
|
|
918
936
|
path to the item and the second is a boolean which will be true if the item is
|
|
919
937
|
a directory. If the function returns true, the item will be uploaded,
|
|
920
|
-
otherwise it will be filtered out and ignored.
|
|
938
|
+
otherwise it will be filtered out and ignored. The ~useFastput~ option is a
|
|
939
|
+
boolean option. If ~true~, the method will use the faster, but less supported,
|
|
940
|
+
~fastPut()~ method to transfer files. The default is to use the slightly slower,
|
|
941
|
+
but better supported, ~put()~ method.
|
|
921
942
|
|
|
922
943
|
**** Example
|
|
923
944
|
|
|
@@ -969,7 +990,7 @@ supported at this time.
|
|
|
969
990
|
|
|
970
991
|
#+end_src
|
|
971
992
|
|
|
972
|
-
*** downloadDir(srcDir, dstDir,
|
|
993
|
+
*** downloadDir(srcDir, dstDir, options) ==> string
|
|
973
994
|
|
|
974
995
|
Download the remote directory specified by ~srcDir~ to the local file system
|
|
975
996
|
directory specified by ~dstDir~. The ~dstDir~ directory will be created if
|
|
@@ -984,20 +1005,30 @@ the remote file that has been downloaded and the destination is the local path
|
|
|
984
1005
|
to where the file was downloaded to. You can add a listener for this event using
|
|
985
1006
|
the ~on()~ method.
|
|
986
1007
|
|
|
987
|
-
The
|
|
988
|
-
|
|
989
|
-
|
|
1008
|
+
The ~options~ argument is an options object with two supported properties, ~filter~
|
|
1009
|
+
and ~useFastget~. The ~filter~ argument is a predicate function which will be called
|
|
1010
|
+
with two arguments for each potential item to be downloaded. The first argument
|
|
1011
|
+
is the full path of the item and the second argument is a boolean, which will be
|
|
990
1012
|
true if the item is a directory. If the function returns true, the item will be
|
|
991
1013
|
included in the download. If it returns false, it will be filtered and ignored.
|
|
992
1014
|
The filter function is called via the ~Array.filter~ method. These array
|
|
993
1015
|
comprehension methods are known to be unsafe for asynchronous functions.
|
|
994
1016
|
Therefore, only synchronous filter functions are supported at this time.
|
|
995
1017
|
|
|
1018
|
+
If the ~useFastget~ property is set to ~true~, the method will use ~fastGet()~ to
|
|
1019
|
+
transfer files. The ~fastGet~ method is faster, but not supported by all SFTP
|
|
1020
|
+
services.
|
|
1021
|
+
|
|
996
1022
|
- srcDir :: A remote file path specified as a string
|
|
997
1023
|
- dstDir :: A local file path specified as a string
|
|
998
|
-
-
|
|
1024
|
+
- options :: An object with two supported properties, ~filter~ and ~useFastget~. The
|
|
1025
|
+
filter property is a function accepting two arguments, the full path to an
|
|
999
1026
|
item and a boolean value which will be true if the item is a directory. The
|
|
1000
|
-
function is called for each item in the download path
|
|
1027
|
+
function is called for each item in the download path and should return true
|
|
1028
|
+
to include the item and false to exclude it in the download. The ~useFastget~
|
|
1029
|
+
property is a boolean. If true, the ~fastGet()~ method will be used to transfer
|
|
1030
|
+
files. If ~false~ (the default), the slower but better supported ~get()~ mehtod is
|
|
1031
|
+
used. .
|
|
1001
1032
|
|
|
1002
1033
|
**** Example
|
|
1003
1034
|
|
|
@@ -1047,6 +1078,52 @@ Therefore, only synchronous filter functions are supported at this time.
|
|
|
1047
1078
|
|
|
1048
1079
|
#+end_src
|
|
1049
1080
|
|
|
1081
|
+
|
|
1082
|
+
*** createReadStream(remotePath, options)) ==> stream object
|
|
1083
|
+
|
|
1084
|
+
Returns a read stream object which is attached to the remote file specified by
|
|
1085
|
+
the ~remotePath~ argument. This is a low level method which just returns a read
|
|
1086
|
+
stream object. Client code is fully responsible for managing and releasing the
|
|
1087
|
+
resources associated with the stream once finished i.e. closing files,
|
|
1088
|
+
removing listeners etc.
|
|
1089
|
+
|
|
1090
|
+
- remotePath :: A remote file path specified as a string
|
|
1091
|
+
- options :: An options object. Supported properties are
|
|
1092
|
+
- flags :: defaults to 'r'
|
|
1093
|
+
- encoding :: defaults to null
|
|
1094
|
+
- handle :: defaults to null
|
|
1095
|
+
- mode :: 0o666
|
|
1096
|
+
- autoClose :: defaults to true. If set to false, client code is responsible
|
|
1097
|
+
for closing file descriptors when finished
|
|
1098
|
+
- start :: Default 0. Position to start reading bytes from (inclusive)
|
|
1099
|
+
- end :: Postion to stop reading bytes (inclusive).
|
|
1100
|
+
|
|
1101
|
+
*** createWriteStream(remotePath, options) ==> stream object
|
|
1102
|
+
|
|
1103
|
+
Returns a write stream object which is attached to the remote file specified
|
|
1104
|
+
in the ~remotePath~ argument. This is a low legvel function which just returns
|
|
1105
|
+
the stream object. Client code is fully responsible for managing that object,
|
|
1106
|
+
including closing any file descriptiors and removing listeners etc.
|
|
1107
|
+
|
|
1108
|
+
- remotePath :: Path to the remote file specified as a string
|
|
1109
|
+
- options :: An object containing stream options. Supported properties include
|
|
1110
|
+
- flags :: default 'w'
|
|
1111
|
+
- encoding :: defulat null
|
|
1112
|
+
- mode :: 0o666
|
|
1113
|
+
- autoClose :: true
|
|
1114
|
+
- start :: Byte position to start writing from (inclusive). May require
|
|
1115
|
+
changing flag to 'r+'.
|
|
1116
|
+
|
|
1117
|
+
*** rcopy(srcPath, dstPath) ==> string
|
|
1118
|
+
|
|
1119
|
+
Perfrom a remote file copy. The file identified by the ~srcPath~ argument will
|
|
1120
|
+
be copied to the file specified as the ~dstPath~ argument. The directory where
|
|
1121
|
+
~dstPath~ will be placed must exist, but the actual file must not i.e. no
|
|
1122
|
+
overwrites allowed.
|
|
1123
|
+
|
|
1124
|
+
- srcPath :: Path to remote file to be copied specified as a string
|
|
1125
|
+
- dstPath :: Path to where the copy will be creaeted specified as a string
|
|
1126
|
+
|
|
1050
1127
|
*** end() ==> boolean
|
|
1051
1128
|
|
|
1052
1129
|
Ends the current client session, releasing the client socket and associated
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2-sftp-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "ssh2 sftp client for node",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"chai-subset": "^1.6.0",
|
|
36
36
|
"checksum": "^1.0.0",
|
|
37
37
|
"dotenv": "^16.0.0",
|
|
38
|
-
"eslint": "^8.
|
|
38
|
+
"eslint": "^8.17.0",
|
|
39
39
|
"eslint-config-prettier": "^8.5.0",
|
|
40
40
|
"eslint-plugin-mocha": "^10.0.3",
|
|
41
41
|
"eslint-plugin-node": "^11.1.0",
|
|
42
42
|
"eslint-plugin-promise": "^6.0.0",
|
|
43
43
|
"eslint-plugin-unicorn": "^42.0.0",
|
|
44
|
-
"mocha": "^
|
|
44
|
+
"mocha": "^10.0.0",
|
|
45
45
|
"moment": "^2.29.1",
|
|
46
46
|
"nyc": "^15.1.0",
|
|
47
47
|
"prettier": "^2.6.1",
|
|
@@ -51,6 +51,6 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"concat-stream": "^2.0.0",
|
|
53
53
|
"promise-retry": "^2.0.1",
|
|
54
|
-
"ssh2": "^1.
|
|
54
|
+
"ssh2": "^1.11.0"
|
|
55
55
|
}
|
|
56
56
|
}
|