ssh2-sftp-client 9.0.3 → 9.1.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.org CHANGED
@@ -9,87 +9,30 @@ 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 *v9.0.2*.
12
+ Current stable release is *v9.1.0.
13
13
 
14
- Code has been tested against Node versions 14.19.1, 16.15.0 and 18.1.0
14
+ Code has been tested against Node versions 14.21.3, 16.19.1, 18.16.0 and 20.0.0
15
15
 
16
16
  Node versions < 14.x are not supported.
17
17
 
18
- ** Version 9.x Changes
19
- - Fix bug in ~end()~ method where it was possible for the module to attempt calling
20
- the underlying ssh2 ~end()~ method when ssh2 has not been initialised. This could
21
- lead to undefined reference errors.
22
- - Fix bug in ~get()~ method where supplied destination streams were not close, creating
23
- a possible resource leak. If the remote file did not exist, the method would return
24
- an error, but failed to close any passed in stream supplied as the destination for
25
- the data in the ~get()~ call.
26
- - Change the default end and close handlers not to throw error or reject
27
- promises. Previously, an end or close event would cause an error to be raised or a
28
- promise to be rejected if the event was deemed to be /unexpected/. However,
29
- classification of events as being unexpected was unreliable and didn't add much real
30
- value. Both these handlers will now invalidate the sftp connection object and log that
31
- the event fired and nothing else.
32
- - Changed when event handled flags are reset. Now they are reset after a new set of
33
- temporary listeners are added.
34
- - Don't throw an error when calling end() if there is no active sftp connection. It does
35
- no harm to call end() when there is no connection, so no need to raise an error.
36
- - Use nullish coalescing when setting retry parameters instead of or'ing with
37
- defaults. Allows setting values to 0.
38
- - *Breaking Change*: This version uses syntax not supported in node versions
39
- prior to v14. Therefore, node versions less than v14 will not work.
40
- - *Breaking Change*: This ~list()~ method no longer accepts a regular expression
41
- for filtering the entries to be returned. You can now specify a filter
42
- function instead. The function is called for each item in the list of items
43
- to be returned, passing in the item object as its only argument.
44
- Essentially, this is just a call to ~Array.filter()~, so the filter function
45
- should behave in the same way i.e. return true for items to be retained and
46
- false for those to be dropped.
47
- - *Breaking Change*: The ability to set ~autoClose~ on read and write streams and
48
- the ability to set ~end~ on ~pipe~ operations has been removed. These options
49
- caused confusion for users and were too easy to get wrong, plus it made the
50
- methods overly complicated. For those use-cases where you want to control
51
- streams at a low level, two new methods have been added, ~createReadStream()~ and
52
- ~createWriteStream()~. However, it should be noted that client code is 100%
53
- responsible for managing streams obtained using these methods. Use at your
54
- own risk!
55
- - *Breaking Change*: The 3rd argument to ~uploadDir()~ and ~downloadDir()~ methods
56
- has been change. Previously, the argument was a filter function used to
57
- select which directories and files to be transferred. The 3rd argument is
58
- now an options object with two supported properties, ~filter~ and ~useFastput~
59
- (for ~uploadDir()~) or ~useFastget~ (for ~downloadDir()~). If ~useFastput~ is true,
60
- the ~fastPut()~ method will be pused to upload files. If ~false~ or missing, the
61
- slower, but better supported, ~put()~ method will be used. Likewise, the
62
- ~useFastget~ options can be set to ~true~ to use the ~fastGet()~ method for
63
- donwloading files, otherwise the slower, but more reliable, ~get()~ method
64
- will be used.
65
- - The ~uploadDir()~ and ~downloadDir()~ methods now use asynchrounous processes to
66
- upload/download files. This should result in improved performance for these
67
- two methods.
68
- - New Methods: Two new methods, ~createWriteStream()~ and ~createReadStream()~
69
- have been added. These methods will return a stream object connected to a
70
- remote file on the ~sftp~ server. Client code is responsible for managing
71
- these stream objects. This includes adding any necessary event listeners and
72
- disposing of the objects once finished with them.
73
- - Refactoring of Listeners: The library manages temporary listeners in order
74
- to provide a way to catch events and processes them inside a ~Promise~
75
- context. Previously, every method added its own set of temporary listeners.
76
- However, this could result in multiple sets of listeners being added,
77
- especially for methods which call other methods as part of their processing
78
- e.g. ~rmdir(),~ ~uploadDir()~ and ~dowqnloadDir()~. To avoid this, /internal only/
79
- versions of each method have been created. These internal methods use an
80
- /underscore/ ~_~ prefix. Client code should not use these methods directly.
81
- - New method: Added ~rcopy()~ method to perform a remote copy of a file on the remote SFTP server.
82
- - Bumped ssh2 version to 1.11.0
18
+ ** Version 9.1.0 Changes
83
19
 
20
+ - Added lstat() method
21
+ - Fixed bug in option hadnling which was preventing setting file mode in get() and put()
22
+ methods
23
+ - Fixed bug where a loss of network connections between establishment of the connection
24
+ and calling various sftp methods was not handled and could result in an event causing
25
+ the node process to exit with an error.
26
+
84
27
  * Installation
85
28
 
86
29
  #+begin_src shell
87
- npm install ssh2-sftp-client
30
+ npm install ssh2-sftp-client
88
31
  #+end_src
89
32
 
90
33
  * Basic Usage
91
34
 
92
- #+begin_src javascript
35
+ #+begin_src js
93
36
  let Client = require('ssh2-sftp-client');
94
37
  let sftp = new Client();
95
38
 
@@ -151,7 +94,7 @@ All the methods will return a Promise, except for ~on()~ and
151
94
  more robust.
152
95
 
153
96
  When specifying file paths, ensure to include a full path i.e. include the
154
- remote filename. Don't expect the module to append the local file name to the
97
+ remote file name. Don't expect the module to append the local file name to the
155
98
  path you provide. For example, the following will not work
156
99
 
157
100
  #+begin_src javascript
@@ -159,7 +102,7 @@ All the methods will return a Promise, except for ~on()~ and
159
102
  #+end_src
160
103
 
161
104
  will not result in the file ~test.txt~ being copied to
162
- ~/remote/dir/test.txt~. You need to specify the target filename as well e.g.
105
+ ~/remote/dir/test.txt~. You need to specify the target file name as well e.g.
163
106
 
164
107
  #+begin_src javascript
165
108
  client.put('/home/fred/test.txt', '/remote/dir/test.txt');
@@ -247,12 +190,12 @@ for that package for an explanation of these values.
247
190
  privateKey: fs.readFileSync('/path/to/key'), // Buffer or string that contains
248
191
  passphrase: 'a pass phrase', // string - For an encrypted private key
249
192
  readyTimeout: 20000, // integer How long (in ms) to wait for the SSH handshake
250
- strictVendor: true // boolean - Performs a strict server vendor check
251
- debug: myDebug // function - Set this to a function that receives a single
193
+ strictVendor: true, // boolean - Performs a strict server vendor check
194
+ debug: myDebug,// function - Set this to a function that receives a single
252
195
  // string argument to get detailed (local) debug information.
253
- retries: 2 // integer. Number of times to retry connecting
254
- retry_factor: 2 // integer. Time factor used to calculate time between retries
255
- retry_minTimeout: 2000 // integer. Minimum timeout between attempts
196
+ retries: 2, // integer. Number of times to retry connecting
197
+ retry_factor: 2, // integer. Time factor used to calculate time between retries
198
+ retry_minTimeout: 2000, // integer. Minimum timeout between attempts
256
199
  };
257
200
 
258
201
  // rarely used options
@@ -279,7 +222,7 @@ for that package for an explanation of these values.
279
222
 
280
223
  #+begin_src javascript
281
224
  sftp.connect({
282
- host: example.com,
225
+ host: 'example.com',
283
226
  port: 22,
284
227
  username: 'donald',
285
228
  password: 'youarefired'
@@ -310,7 +253,7 @@ directory.
310
253
  password: 'my-secret'
311
254
  };
312
255
 
313
- let sftp = new Client;
256
+ let sftp = new Client();
314
257
 
315
258
  sftp.connect(config)
316
259
  .then(() => {
@@ -333,19 +276,19 @@ The objects in the array returned by ~list()~ have the following properties;
333
276
 
334
277
  #+begin_src javascript
335
278
  {
336
- type: // file type(-, d, l)
337
- name: // file name
338
- size: // file size
339
- modifyTime: // file timestamp of modified time
340
- accessTime: // file timestamp of access time
279
+ type: '-', // file type(-, d, l)
280
+ name: 'example.txt', // file name
281
+ size: 43, // file size
282
+ modifyTime: 1675645360000, // file timestamp of modified time
283
+ accessTime: 1675645360000, // file timestamp of access time
341
284
  rights: {
342
- user:
343
- group:
344
- other:
285
+ user: 'rw',
286
+ group: 'r',
287
+ other: 'r',
345
288
  },
346
- owner: // user ID
347
- group: // group ID
348
- longname: // like ls -l line
289
+ owner: 1000, // user ID
290
+ group: 1000, // group ID
291
+ longname: '-rw-r--r-- 1 fred fred 43 Feb 6 12:02 exaple.txt', // like ls -l line
349
292
  }
350
293
  #+end_src
351
294
 
@@ -366,7 +309,7 @@ if it exists or false if it does not.
366
309
  password: 'my-secret'
367
310
  };
368
311
 
369
- let sftp = new Client;
312
+ let sftp = new Client();
370
313
 
371
314
  sftp.connect(config)
372
315
  .then(() => {
@@ -824,11 +767,11 @@ necessary permissions to modify the remote file.
824
767
  This method uses the openssh POSIX rename extension introduced in OpenSSH 4.8.
825
768
  The advantage of this version of rename over standard SFTP rename is that it is
826
769
  an atomic operation and will allow renaming a resource where the destination
827
- name exists. The POSIX rename will also work on some filesystems which do not
770
+ name exists. The POSIX rename will also work on some file systems which do not
828
771
  support standard SFTP rename because they don't support the system hardlink()
829
772
  call. The POSIX rename extension is available on all openSSH servers from 4.8
830
773
  and some other implementations. This is an extension to the standard SFTP
831
- protocol and therefore is not supported on all sSFTP servers.
774
+ protocol and therefore is not supported on all sftp servers.
832
775
 
833
776
  - fromPath :: string. Path to existing file to be renamed.
834
777
  - toPath :: string. Path for new name. If it already exists, it will be replaced
@@ -1001,7 +944,7 @@ required. All sub directories within ~srcDir~ will also be copied. Any existing
1001
944
  files in the local path will be overwritten. No files in the local path will be
1002
945
  deleted.
1003
946
 
1004
- The method also emites ~download~ events to provide a way to monitor download
947
+ The method also emits ~download~ events to provide a way to monitor download
1005
948
  progress. The download event listener is called with one argument, an object
1006
949
  with two properties, source and destination. The source property is the path to
1007
950
  the remote file that has been downloaded and the destination is the local path
@@ -1030,7 +973,7 @@ services.
1030
973
  function is called for each item in the download path and should return true
1031
974
  to include the item and false to exclude it in the download. The ~useFastget~
1032
975
  property is a boolean. If true, the ~fastGet()~ method will be used to transfer
1033
- files. If ~false~ (the default), the slower but better supported ~get()~ mehtod is
976
+ files. If ~false~ (the default), the slower but better supported ~get()~ method is
1034
977
  used. .
1035
978
 
1036
979
  **** Example
@@ -1098,19 +1041,19 @@ services.
1098
1041
  - autoClose :: defaults to true. If set to false, client code is responsible
1099
1042
  for closing file descriptors when finished
1100
1043
  - start :: Default 0. Position to start reading bytes from (inclusive)
1101
- - end :: Postion to stop reading bytes (inclusive).
1044
+ - end :: Position to stop reading bytes (inclusive).
1102
1045
 
1103
1046
  *** createWriteStream(remotePath, options) ==> stream object
1104
1047
 
1105
1048
  Returns a write stream object which is attached to the remote file specified
1106
- in the ~remotePath~ argument. This is a low legvel function which just returns
1049
+ in the ~remotePath~ argument. This is a low level function which just returns
1107
1050
  the stream object. Client code is fully responsible for managing that object,
1108
- including closing any file descriptiors and removing listeners etc.
1051
+ including closing any file descriptors and removing listeners etc.
1109
1052
 
1110
1053
  - remotePath :: Path to the remote file specified as a string
1111
1054
  - options :: An object containing stream options. Supported properties include
1112
1055
  - flags :: default 'w'
1113
- - encoding :: defulat null
1056
+ - encoding :: default null
1114
1057
  - mode :: 0o666
1115
1058
  - autoClose :: true
1116
1059
  - start :: Byte position to start writing from (inclusive). May require
@@ -1118,13 +1061,13 @@ services.
1118
1061
 
1119
1062
  *** rcopy(srcPath, dstPath) ==> string
1120
1063
 
1121
- Perfrom a remote file copy. The file identified by the ~srcPath~ argument will
1064
+ Perform a remote file copy. The file identified by the ~srcPath~ argument will
1122
1065
  be copied to the file specified as the ~dstPath~ argument. The directory where
1123
1066
  ~dstPath~ will be placed must exist, but the actual file must not i.e. no
1124
1067
  overwrites allowed.
1125
1068
 
1126
1069
  - srcPath :: Path to remote file to be copied specified as a string
1127
- - dstPath :: Path to where the copy will be creaeted specified as a string
1070
+ - dstPath :: Path to where the copy will be created specified as a string
1128
1071
 
1129
1072
  *** end() ==> boolean
1130
1073
 
@@ -1173,12 +1116,13 @@ Removes the specified listener from the event specified in eventType. Note that
1173
1116
  the ~end()~ method automatically removes all listeners from the client object.
1174
1117
 
1175
1118
  * Platform Quirks & Warnings
1119
+
1176
1120
  ** Server Capabilities
1177
1121
 
1178
1122
  All SFTP servers and platforms are not equal. Some facilities provided by
1179
1123
  ~ssh2-sftp-client~ either depend on capabilities of the remote server or the
1180
1124
  underlying capabilities of the remote server platform. As an example,
1181
- consider ~chmod()~. This command depends on a remote filesystem which
1125
+ consider ~chmod()~. This command depends on a remote file system which
1182
1126
  implements the 'nix' concept of users and groups. The /win32/ platform does
1183
1127
  not have the same concept of users and groups, so ~chmod()~ will not behave
1184
1128
  in the same way.
@@ -1200,7 +1144,7 @@ the ~end()~ method automatically removes all listeners from the client object.
1200
1144
  concurrent connections and some are known to have issues with negotiating
1201
1145
  packet sizes. These issues can sometimes be resolved by tweaking the options
1202
1146
  supplied to the methods, such as setting number of concurrent connections or
1203
- a psecific packet size.
1147
+ a specific packet size.
1204
1148
 
1205
1149
  To see an example of the type of issues you can observe with ~fastPut()~ or
1206
1150
  ~fastGet()~, have a look at [[https://github.com/theophilusx/ssh2-sftp-client/issues/407][issue 407]], which describes the experiences of one
@@ -1226,7 +1170,7 @@ the ~end()~ method automatically removes all listeners from the client object.
1226
1170
  =resolve= and =reject=. Only one can be called - once you call =resolve=, you
1227
1171
  cannot call =reject= (well, you can call it, but it won't have any impact on
1228
1172
  the fulfilment status of the promise). The problem arises when an event, for
1229
- exmaple an =error= event is fired either after you have resolved a promise or
1173
+ example an =error= event is fired either after you have resolved a promise or
1230
1174
  possibly in-between promises. If you don't catch the =error= event, your
1231
1175
  script will likely crash with an =uncaught exception= error.
1232
1176
 
@@ -1248,7 +1192,7 @@ the ~end()~ method automatically removes all listeners from the client object.
1248
1192
 
1249
1193
  To handle this, =ssh2-sftp-client= implements a couple of strategies.
1250
1194
  Firstly, when you call one of the module's methods, it adds =error=, =end=
1251
- and =close= event listeners which will call the =reject= moethod on the
1195
+ and =close= event listeners which will call the =reject= method on the
1252
1196
  enclosing promise. It also keeps track of whether an error has been handled
1253
1197
  and if it has, it ignores any subsequent errors until the promise ends.
1254
1198
  Typically, the first error caught has the most relevant information and any
@@ -1265,7 +1209,7 @@ the ~end()~ method automatically removes all listeners from the client object.
1265
1209
  until all events have been caught.
1266
1210
 
1267
1211
  The other area where additional events are fired is during the end() call. To
1268
- deal with these events, the =end()= method setus up listeners which will
1212
+ deal with these events, the =end()= method sets up listeners which will
1269
1213
  simply ignore additional =error=, =end= and =close= events. It is assumed
1270
1214
  that once you have called =end()= you really only care about any main error
1271
1215
  which occurs and no longer care about other errors that may be raised as the
@@ -1350,7 +1294,7 @@ openSSH is =10:30:60=, so you really just need to have enough delay to ensure
1350
1294
  that the 1st connection has completed authentication before the 11th connection
1351
1295
  is attempted.
1352
1296
 
1353
- ** How can I pass writable stream as dst for get method?
1297
+ ** How can I pass writeable stream as dst for get method?
1354
1298
 
1355
1299
  If the dst argument passed to the get method is a writeable stream, the remote
1356
1300
  file will be piped into that writeable. If the writeable you pass in is a
@@ -1495,7 +1439,7 @@ documentation for details. Getting these parameters correct usually resolves the
1495
1439
  issue.
1496
1440
 
1497
1441
  When encountering this type of problem, one worthwhile approach is to use
1498
- openSSH's CLI sftp program with the =-v= switch to raise loggin levels. This
1442
+ openSSH's CLI sftp program with the =-v= switch to raise logging levels. This
1499
1443
  will show you what algorithms the CLI is using. You can then use this
1500
1444
  information to match the names with the accepted algorithm names documented in
1501
1445
  the =ssh2= README to set the properties in the =algorithms= object.
@@ -1541,6 +1485,7 @@ the =ssh2= README to set the properties in the =algorithms= object.
1541
1485
  await client.end();
1542
1486
  }
1543
1487
  #+end_src
1488
+
1544
1489
  ** Connection hangs or fails for larger files
1545
1490
 
1546
1491
  This was contributed by Ladislav Jacho. Thanks.
@@ -1554,6 +1499,13 @@ the =ssh2= README to set the properties in the =algorithms= object.
1554
1499
 
1555
1500
  For more explanation, see [[https://github.com/theophilusx/ssh2-sftp-client/issues/342][issue #342]].
1556
1501
 
1502
+ ** Typescript definition file out of date
1503
+
1504
+ This project does not use Typescript. However, typescript definition files are provided by
1505
+ other 3rd parties. Sometimes, these definition files have not stayed up-to-date with the
1506
+ current version of this module. If you encounter this issue, you need to report it to the
1507
+ party responsible for the definition file, not this project.
1508
+
1557
1509
  * Examples
1558
1510
 
1559
1511
  I have started collecting example scripts in the example directory of the
@@ -1603,7 +1555,7 @@ the ~ssh2-sftp-client~ wrapper module.
1603
1555
  ** Common Errors
1604
1556
 
1605
1557
  There are some common errors people tend to make when using Promises or
1606
- Asyc/Await. These are by far the most common problem found in issues logged
1558
+ Async/Await. These are by far the most common problem found in issues logged
1607
1559
  against this module. Please check for some of these before logging your
1608
1560
  issue.
1609
1561
 
@@ -1727,7 +1679,7 @@ the ~ssh2-sftp-client~ wrapper module.
1727
1679
  await sftp.fastGet(`${d}/foo.txt`, 'bat.txt');
1728
1680
  } catch (e) {
1729
1681
  console.error(e.message);
1730
- } finally () {
1682
+ } finally {
1731
1683
  await sftp.end();
1732
1684
  }
1733
1685
  }
@@ -1743,7 +1695,7 @@ the ~ssh2-sftp-client~ wrapper module.
1743
1695
 
1744
1696
  The basic problem is that the try/catch block will have completed execution
1745
1697
  before the asynchronous code has completed. If the asynchronous code has not
1746
- compleed, then there is a potential for it to raise an error. However, as
1698
+ completed, then there is a potential for it to raise an error. However, as
1747
1699
  the try/catch block has already completed, there is no /catch/ waiting to
1748
1700
  catch the error. It will bubble up and probably result in your script
1749
1701
  exiting with an uncaught exception error.
@@ -1833,6 +1785,7 @@ based on messages which start with 'CLIENT' e.g.
1833
1785
  }
1834
1786
  }
1835
1787
  #+end_src
1788
+
1836
1789
  * Logging Issues
1837
1790
 
1838
1791
  Please log an issue for all bugs, questions, feature and enhancement
@@ -1877,8 +1830,10 @@ your pull request what level of change it represents i.e.
1877
1830
 
1878
1831
  - Major :: Change to API or major change in functionality which will require an
1879
1832
  increase in major version number.
1833
+
1880
1834
  - Minor :: Minor change, enhancement or new feature which does not change
1881
1835
  existing API and will not break existing client code.
1836
+
1882
1837
  - Bug Fix :: No change to functionality or features. Simple fix of an existing
1883
1838
  bug.
1884
1839
 
@@ -1910,3 +1865,4 @@ Thanks to the following for their contributions -
1910
1865
  Also included test to check for this regression in future.
1911
1866
  - cakemasher :: Contributed fix for removeTempListeners().
1912
1867
 
1868
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh2-sftp-client",
3
- "version": "9.0.3",
3
+ "version": "9.1.0",
4
4
  "description": "ssh2 sftp client for node",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -40,7 +40,7 @@
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
- "eslint-plugin-unicorn": "^43.0.2",
43
+ "eslint-plugin-unicorn": "^46.0.0",
44
44
  "mocha": "^10.0.0",
45
45
  "moment": "^2.29.1",
46
46
  "nyc": "^15.1.0",
@@ -51,6 +51,6 @@
51
51
  "dependencies": {
52
52
  "concat-stream": "^2.0.0",
53
53
  "promise-retry": "^2.0.1",
54
- "ssh2": "^1.11.0"
54
+ "ssh2": "^1.12.0"
55
55
  }
56
56
  }