ssh2-sftp-client 5.3.1 → 5.3.2

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/CHANGELOG.org CHANGED
@@ -1,38 +1,42 @@
1
1
  * Change Logging
2
2
 
3
- ** V5.3.1 (Prod Version)
3
+ ** Version 5.3.2 (Prod Version)
4
+ - Minor README typo fixes
5
+ - Fix error in local file path checks (#294)
6
+
7
+ ** V5.3.1
4
8
  - Fix bug in handling of relative local paths
5
9
  - Change handling of stream closures in ~get()~ and ~put()~ methods
6
10
 
7
- ** v5.3.0
11
+ ** v5.3.0
8
12
  - Refine event handler management
9
13
  - Fix path processing for win32 based sftp servers
10
- - Update documentation
11
- ** v5.2.2
14
+ - Update documentation
15
+ ** v5.2.2
12
16
  - Bug fix release. Add error code 4 check to stat() method.
13
17
  - bump Mocha version for tests
14
18
 
15
19
  ** v5.2.1
16
20
  - Move some dependencies into dev-Dependencies
17
- ** v5.2.0
18
- - Add new method posixRename() which uses the openSSH POSIX rename extension.
21
+ ** v5.2.0
22
+ - Add new method posixRename() which uses the openSSH POSIX rename extension.
19
23
  ** v5.1.3
20
24
  - Fix bug when writing to root directory and failure due to not being able to
21
25
  determine parent
22
26
  - Refactor some tests to eliminate need to have artificial delays between
23
27
  tests
24
28
  - Bumped some dependency versions to latest version
25
- ** v5.1.2
29
+ ** v5.1.2
26
30
  - Added back global close handler
27
31
  - Added dumpListeners() method
28
-
29
- ** v5.1.1
30
- - Added separate close handlers to each method.
32
+
33
+ ** v5.1.1
34
+ - Added separate close handlers to each method.
31
35
  - Added missing return statement in connect method
32
- - Added additional troubleshooting documentation for
36
+ - Added additional troubleshooting documentation for
33
37
  common errors.
34
38
 
35
- ** v5.1.0
39
+ ** v5.1.0
36
40
  - Fix bug in checkRemotePath() relating to handling of badly
37
41
  specified paths (issue #213)
38
42
  - Added additional debugging support
package/README.md CHANGED
@@ -17,6 +17,7 @@
17
17
  - [Version 5.2.2](#sec-4-11)
18
18
  - [Version 5.3.0](#sec-4-12)
19
19
  - [Version 5.3.1](#sec-4-13)
20
+ - [Version 5.3.2](#sec-4-14)
20
21
  - [Documentation](#sec-5)
21
22
  - [Specifying Paths](#sec-5-1)
22
23
  - [Methods](#sec-5-2)
@@ -72,7 +73,7 @@ an SFTP client for node.js, a wrapper around [SSH2](https://github.com/mscdex/ss
72
73
 
73
74
  Documentation on the methods and available options in the underlying modules can be found on the [SSH2](https://github.com/mscdex/ssh2) and [SSH2-STREAMS](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) project pages.
74
75
 
75
- Current stable release is **v5.3.1**.
76
+ Current stable release is **v5.3.2**.
76
77
 
77
78
  Code has been tested against Node versions 12.18.2 and 13.14.0
78
79
 
@@ -82,6 +83,12 @@ Node versions < 10.x are not supported.
82
83
 
83
84
  A bug report hass been logged against the ssh2-streams library as [issue 156](https://github.com/mscdex/ssh2-streams/issues/156).
84
85
 
86
+ <span class="underline">UPDATE</span>: The author of the upstream ssh2 and ssh2-streams module has decided on a re-write of the ssh2 module to address the above issues as well as some other design limitations and to allow the module to better fit in with newer versions of node. As part of that process, the functionality of ssh2-streams is being incorporated into the main ssh2 module and the ssh2-streams module is being deprecated. This will require a significant update to this module and may result in some API changes, depending on what changes in the re-write of ssh2.
87
+
88
+ To support these changes, a new branch called *version-6* has been created. This branch will use the newest version of ssh2 and for now is very much experimental and subject to change.
89
+
90
+ <span class="underline">UPDATE</span>: Apparently the change in core node which cause the issue with ssh2 has been rolled back in node version 15.3.0. Testing seems to indicate the above issue does not exist in that version of node.
91
+
85
92
  # Installation<a id="sec-2"></a>
86
93
 
87
94
  ```shell
@@ -213,6 +220,11 @@ In addition to the Promise error handlers, there is a default error handler whic
213
220
  - Fix bug in handling of relative local paths
214
221
  - Modified `get()` and `put()` methods to support special purpose streams which require `autoClose` to be `false`. These methods will now look for the `autoClose: false` property in the options object and if it is false, will issue a `destroy()` on the underlying stream just before the promise is resolved. The default is `autoClose: true` and this default should be used unless there is a known specific reason to change it to false.
215
222
 
223
+ ## Version 5.3.2<a id="sec-4-14"></a>
224
+
225
+ - Minor README typo fixes
226
+ - Fix error in local file path checks (#294)
227
+
216
228
  # Documentation<a id="sec-5"></a>
217
229
 
218
230
  The connection options are the same as those offered by the underlying SSH2 module. For full details, please see [SSH2 client methods](https://github.com/mscdex/ssh2#user-content-client-methods)
@@ -263,17 +275,17 @@ Constructor to create a new `ssh2-sftp-client` object. An optional `name` string
263
275
 
264
276
  ```javascript
265
277
  'use strict';
266
-
278
+
267
279
  const Client = require('ssh2-sftp-client');
268
-
280
+
269
281
  const config = {
270
282
  host: 'example.com',
271
283
  username: 'donald',
272
284
  password: 'my-secret'
273
285
  };
274
-
286
+
275
287
  const sftp = new Client('example-client');
276
-
288
+
277
289
  sftp.connect(config)
278
290
  .then(() => {
279
291
  return sftp.cwd();
@@ -294,12 +306,12 @@ Connect to an sftp server. Full documentation for connection options is availabl
294
306
  1. Connection Options
295
307
 
296
308
  This module is based on the excellent [SSH2](https://github.com/mscdex/ssh2#client) module. That module is a general SSH2 client and server library and provides much more functionality than just SFTP connectivity. Many of the connect options provided by that module are less relevant for SFTP connections. It is recommended you keep the config options to the minimum needed and stick to the options listed in the `commonOpts` below.
297
-
309
+
298
310
  The `retries`, `retry_factor` and `retry_minTimeout` options are not part of the SSH2 module. These are part of the configuration for the [retry](https://www.npmjs.com/package/retry) package and what is used to enable retrying of sftp connection attempts. See the documentation for that package for an explanation of these values.
299
-
311
+
300
312
  ```javascript
301
313
  // common options
302
-
314
+
303
315
  let commonOpts {
304
316
  host: 'localhost', // string Hostname or IP of server.
305
317
  port: 22, // Port number of the server.
@@ -309,7 +321,7 @@ Connect to an sftp server. Full documentation for connection options is availabl
309
321
  password: 'borsch', // string Password for password-based user authentication
310
322
  agent: process.env.SSH_AGENT, // string - Path to ssh-agent's UNIX socket
311
323
  privateKey: fs.readFileSync('/path/to/key'), // Buffer or string that contains
312
- passphrase; 'a pass phrase', // string - For an encrypted private key
324
+ passphrase: 'a pass phrase', // string - For an encrypted private key
313
325
  readyTimeout: 20000, // integer How long (in ms) to wait for the SSH handshake
314
326
  strictVendor: true // boolean - Performs a strict server vendor check
315
327
  debug: myDebug // function - Set this to a function that receives a single
@@ -318,9 +330,9 @@ Connect to an sftp server. Full documentation for connection options is availabl
318
330
  retry_factor: 2 // integer. Time factor used to calculate time between retries
319
331
  retry_minTimeout: 2000 // integer. Minimum timeout between attempts
320
332
  };
321
-
333
+
322
334
  // rarely used options
323
-
335
+
324
336
  let advancedOpts {
325
337
  localAddress,
326
338
  localPort,
@@ -361,16 +373,16 @@ Retrieves a directory listing. This method returns a Promise, which once realise
361
373
 
362
374
  ```javascript
363
375
  const Client = require('ssh2-sftp-client');
364
-
376
+
365
377
  const config = {
366
378
  host: 'example.com',
367
379
  port: 22,
368
380
  username: 'red-don',
369
381
  password: 'my-secret'
370
382
  };
371
-
383
+
372
384
  let sftp = new Client;
373
-
385
+
374
386
  sftp.connect(config)
375
387
  .then(() => {
376
388
  return sftp.list('/path/to/remote/dir');
@@ -389,7 +401,7 @@ Retrieves a directory listing. This method returns a Promise, which once realise
389
401
  2. Return Objects
390
402
 
391
403
  The objects in the array returned by `list()` have the following properties;
392
-
404
+
393
405
  ```javascript
394
406
  {
395
407
  type: // file type(-, d, l)
@@ -410,11 +422,11 @@ Retrieves a directory listing. This method returns a Promise, which once realise
410
422
  3. Pattern Filter
411
423
 
412
424
  The filter options can be a regular expression (most powerful option) or a simple *glob*-like string where \* will match any number of characters, e.g.
413
-
425
+
414
426
  foo* => foo, foobar, foobaz
415
427
  *bar => bar, foobar, tabbar
416
428
  *oo* => foo, foobar, look, book
417
-
429
+
418
430
  The *glob*-style matching is very simple. In most cases, you are best off using a real regular expression which will allow you to do more powerful matching and anchor matches to the beginning/end of the string etc.
419
431
 
420
432
  ### exists(path) ==> boolean<a id="sec-5-2-4"></a>
@@ -425,16 +437,16 @@ Tests to see if remote file or directory exists. Returns type of remote object i
425
437
 
426
438
  ```javascript
427
439
  const Client = require('ssh2-sftp-client');
428
-
440
+
429
441
  const config = {
430
442
  host: 'example.com',
431
443
  port: 22,
432
444
  username: 'red-don',
433
445
  password: 'my-secret'
434
446
  };
435
-
447
+
436
448
  let sftp = new Client;
437
-
449
+
438
450
  sftp.connect(config)
439
451
  .then(() => {
440
452
  return sftp.exists('/path/to/remote/dir');
@@ -459,7 +471,7 @@ Returns the attributes associated with the object pointed to by `path`.
459
471
  1. Attributes
460
472
 
461
473
  The `stat()` method returns an object with the following properties;
462
-
474
+
463
475
  ```javascript
464
476
  let stats = {
465
477
  mode: 33279, // integer representing type and permissions
@@ -482,7 +494,7 @@ Returns the attributes associated with the object pointed to by `path`.
482
494
 
483
495
  ```javascript
484
496
  let client = new Client();
485
-
497
+
486
498
  client.connect(config)
487
499
  .then(() => {
488
500
  return client.stat('/path/to/remote/file');
@@ -511,7 +523,7 @@ In general, if your going to pass in a string as the destination, you are better
511
523
  1. Options
512
524
 
513
525
  The options object can be used to pass options to the underlying readStream used to read the data from the remote server.
514
-
526
+
515
527
  ```javascript
516
528
  {
517
529
  flags: 'r',
@@ -521,17 +533,17 @@ In general, if your going to pass in a string as the destination, you are better
521
533
  autoClose: true
522
534
  }
523
535
  ```
524
-
536
+
525
537
  Most of the time, you won't want to use any options. Sometimes, it may be useful to set the encoding. For example, to 'utf-8'. However, it is important not to do this for binary files to avoid data corruption.
526
538
 
527
539
  2. Example Use
528
540
 
529
541
  ```javascript
530
542
  let client = new Client();
531
-
543
+
532
544
  let remotePath = '/remote/server/path/file.txt';
533
545
  let dst = fs.createWriteStream('/local/file/path/copy.txt');
534
-
546
+
535
547
  client.connect(config)
536
548
  .then(() => {
537
549
  return client.get(remotePath, dst);
@@ -543,7 +555,7 @@ In general, if your going to pass in a string as the destination, you are better
543
555
  console.error(err.message);
544
556
  });
545
557
  ```
546
-
558
+
547
559
  - **Tip:** See examples file in the Git repository for more examples. You can pass any writeable stream in as the destination. For example, if you pass in `zlib.createGunzip()` writeable stream, you can both download and decompress a gzip file 'on the fly'.
548
560
 
549
561
  ### fastGet(remotePath, localPath, options) ===> string<a id="sec-5-2-7"></a>
@@ -564,7 +576,7 @@ Downloads a file at remotePath to localPath using parallel reads for faster thro
564
576
  // chunk is transferred
565
577
  }
566
578
  ```
567
-
579
+
568
580
  - **Warning:** Some servers do not respond correctly to requests to alter chunk size. This can result in lost or corrupted data.
569
581
 
570
582
  2. Sample Use
@@ -573,7 +585,7 @@ Downloads a file at remotePath to localPath using parallel reads for faster thro
573
585
  let client = new Client();
574
586
  let remotePath = '/server/path/file.txt';
575
587
  let localPath = '/local/path/file.txt';
576
-
588
+
577
589
  client.connect(config)
578
590
  .then(() => {
579
591
  client.fastGet(remotePath, localPath);
@@ -597,7 +609,7 @@ Upload data from local system to remote server. If the `src` argument is a strin
597
609
  1. Options
598
610
 
599
611
  The following options are supported;
600
-
612
+
601
613
  ```javascript
602
614
  {
603
615
  flags: 'w', // w - write and a - append
@@ -606,17 +618,17 @@ Upload data from local system to remote server. If the `src` argument is a strin
606
618
  autoClose: true // automatically close the write stream when finished
607
619
  }
608
620
  ```
609
-
621
+
610
622
  The most common options to use are mode and encoding. The values shown above are the defaults. You do not have to set encoding to utf-8 for text files, null is fine for all file types. However, using utf-8 encoding for binary files will often result in data corruption.
611
623
 
612
624
  2. Example Use
613
625
 
614
626
  ```javascript
615
627
  let client = new Client();
616
-
628
+
617
629
  let data = fs.createReadStream('/path/to/local/file.txt');
618
630
  let remote = '/path/to/remote/file.txt';
619
-
631
+
620
632
  client.connect(config)
621
633
  .then(() => {
622
634
  return client.put(data, remote);
@@ -628,7 +640,7 @@ Upload data from local system to remote server. If the `src` argument is a strin
628
640
  console.error(err.message);
629
641
  });
630
642
  ```
631
-
643
+
632
644
  - **Tip:** If the src argument is a path string, consider just using `fastPut()`.
633
645
 
634
646
  ### fastPut(localPath, remotePath, options) ==> string<a id="sec-5-2-9"></a>
@@ -650,7 +662,7 @@ Uploads the data in file at `localPath` to a new file on remote server at `remot
650
662
  // a part of a file was transferred
651
663
  }
652
664
  ```
653
-
665
+
654
666
  - **Warning:** There have been reports that some SFTP servers will not honour requests for non-default chunk sizes. This can result in data loss or corruption.
655
667
 
656
668
  2. Example Use
@@ -659,7 +671,7 @@ Uploads the data in file at `localPath` to a new file on remote server at `remot
659
671
  let localFile = '/path/to/file.txt';
660
672
  let remoteFile = '/path/to/remote/file.txt';
661
673
  let client = new Client();
662
-
674
+
663
675
  client.connect(config)
664
676
  .then(() => {
665
677
  client.fastPut(localFile, remoteFile);
@@ -683,7 +695,7 @@ Append the `input` data to an existing remote file. There is no integrity checki
683
695
  1. Options
684
696
 
685
697
  The following options are supported;
686
-
698
+
687
699
  ```javascript
688
700
  {
689
701
  flags: 'a', // w - write and a - append
@@ -692,7 +704,7 @@ Append the `input` data to an existing remote file. There is no integrity checki
692
704
  autoClose: true // automatically close the write stream when finished
693
705
  }
694
706
  ```
695
-
707
+
696
708
  The most common options to use are mode and encoding. The values shown above are the defaults. You do not have to set encoding to utf-8 for text files, null is fine for all file types. Generally, I would not attempt to append binary files.
697
709
 
698
710
  2. Example Use
@@ -700,7 +712,7 @@ Append the `input` data to an existing remote file. There is no integrity checki
700
712
  ```javascript
701
713
  let remotePath = '/path/to/remote/file.txt';
702
714
  let client = new Client();
703
-
715
+
704
716
  client.connect(config)
705
717
  .then(() => {
706
718
  return client.append(Buffer.from('Hello world'), remotePath);
@@ -725,7 +737,7 @@ Create a new directory. If the recursive flag is set to true, the method will cr
725
737
  ```javascript
726
738
  let remoteDir = '/path/to/new/dir';
727
739
  let client = new Client();
728
-
740
+
729
741
  client.connect(config)
730
742
  .then(() => {
731
743
  return client.mkdir(remoteDir, true);
@@ -752,7 +764,7 @@ Remove a directory. If removing a directory and recursive flag is set to `true`,
752
764
  ```javascript
753
765
  let remoteDir = '/path/to/remote/dir';
754
766
  let client = new Client();
755
-
767
+
756
768
  client.connect(config)
757
769
  .then(() => {
758
770
  return client.rmdir(remoteDir, true);
@@ -776,7 +788,7 @@ Delete a file on the remote server.
776
788
  ```javascript
777
789
  let remoteFile = '/path/to/remote/file.txt';
778
790
  let client = new Client();
779
-
791
+
780
792
  client.connect(config)
781
793
  .then(() => {
782
794
  return client.delete(remoteFile);
@@ -802,7 +814,7 @@ Rename a file or directory from `fromPath` to `toPath`. You must have the necess
802
814
  let from = '/remote/path/to/old.txt';
803
815
  let to = '/remote/path/to/new.txt';
804
816
  let client = new Client();
805
-
817
+
806
818
  client.connect(config)
807
819
  .then(() => {
808
820
  return client.rename(from, to);
@@ -850,9 +862,9 @@ Change the mode (read, write or execute permissions) of a remote file or directo
850
862
 
851
863
  ```javascript
852
864
  let path = '/path/to/remote/file.txt';
853
- let ndwMode = 0o644; // rw-r-r
865
+ let newMode = 0o644; // rw-r-r
854
866
  let client = new Client();
855
-
867
+
856
868
  client.connect(config)
857
869
  .then(() => {
858
870
  return client.chmod(path, newMode);
@@ -890,28 +902,28 @@ The upload process also emits 'upload' events. These events are fired for each s
890
902
 
891
903
  ```javascript
892
904
  'use strict';
893
-
905
+
894
906
  // Example of using the uploadDir() method to upload a directory
895
907
  // to a remote SFTP server
896
-
908
+
897
909
  const path = require('path');
898
910
  const SftpClient = require('../src/index');
899
-
911
+
900
912
  const dotenvPath = path.join(__dirname, '..', '.env');
901
913
  require('dotenv').config({path: dotenvPath});
902
-
914
+
903
915
  const config = {
904
916
  host: process.env.SFTP_SERVER,
905
917
  username: process.env.SFTP_USER,
906
918
  password: process.env.SFTP_PASSWORD,
907
919
  port: process.env.SFTP_PORT || 22
908
920
  };
909
-
921
+
910
922
  async function main() {
911
923
  const client = new SftpClient('upload-test');
912
924
  const src = path.join(__dirname, '..', 'test', 'testData', 'upload-src');
913
925
  const dst = '/home/tim/upload-test';
914
-
926
+
915
927
  try {
916
928
  await client.connect(config);
917
929
  client.on('upload', info => {
@@ -923,7 +935,7 @@ The upload process also emits 'upload' events. These events are fired for each s
923
935
  client.end();
924
936
  }
925
937
  }
926
-
938
+
927
939
  main()
928
940
  .then(msg => {
929
941
  console.log(msg);
@@ -931,7 +943,7 @@ The upload process also emits 'upload' events. These events are fired for each s
931
943
  .catch(err => {
932
944
  console.log(`main error: ${err.message}`);
933
945
  });
934
-
946
+
935
947
  ```
936
948
 
937
949
  ### downloadDir(srcDir, dstDir) ==> string<a id="sec-5-2-20"></a>
@@ -947,28 +959,28 @@ The method also emites `download` events to provide a way to monitor download pr
947
959
 
948
960
  ```javascript
949
961
  'use strict';
950
-
962
+
951
963
  // Example of using the downloadDir() method to upload a directory
952
964
  // to a remote SFTP server
953
-
965
+
954
966
  const path = require('path');
955
967
  const SftpClient = require('../src/index');
956
-
968
+
957
969
  const dotenvPath = path.join(__dirname, '..', '.env');
958
970
  require('dotenv').config({path: dotenvPath});
959
-
971
+
960
972
  const config = {
961
973
  host: process.env.SFTP_SERVER,
962
974
  username: process.env.SFTP_USER,
963
975
  password: process.env.SFTP_PASSWORD,
964
976
  port: process.env.SFTP_PORT || 22
965
977
  };
966
-
978
+
967
979
  async function main() {
968
980
  const client = new SftpClient('upload-test');
969
981
  const dst = '/tmp';
970
982
  const src = '/home/tim/upload-test';
971
-
983
+
972
984
  try {
973
985
  await client.connect(config);
974
986
  client.on('download', info => {
@@ -980,7 +992,7 @@ The method also emites `download` events to provide a way to monitor download pr
980
992
  client.end();
981
993
  }
982
994
  }
983
-
995
+
984
996
  main()
985
997
  .then(msg => {
986
998
  console.log(msg);
@@ -988,7 +1000,7 @@ The method also emites `download` events to provide a way to monitor download pr
988
1000
  .catch(err => {
989
1001
  console.log(`main error: ${err.message}`);
990
1002
  });
991
-
1003
+
992
1004
  ```
993
1005
 
994
1006
  ### end() ==> boolean<a id="sec-5-2-21"></a>
@@ -999,7 +1011,7 @@ Ends the current client session, releasing the client socket and associated reso
999
1011
 
1000
1012
  ```javascript
1001
1013
  let client = new Client();
1002
-
1014
+
1003
1015
  client.connect(config)
1004
1016
  .then(() => {
1005
1017
  // do some sftp stuff
@@ -1270,7 +1282,7 @@ sftp.connect(config)
1270
1282
  });
1271
1283
  ```
1272
1284
 
1273
- In the above code, the `sftp.end()` method will almost certainly be called before `sftp.gastGet()` has been fulfilled (unless the *foo.txt* file is really small!). In fact, the whole promise chain will complete and exit even before the `sftp.end()` call has been fulfilled. The correct code would be something like
1285
+ In the above code, the `sftp.end()` method will almost certainly be called before `sftp.fastGet()` has been fulfilled (unless the *foo.txt* file is really small!). In fact, the whole promise chain will complete and exit even before the `sftp.end()` call has been fulfilled. The correct code would be something like
1274
1286
 
1275
1287
  ```javascript
1276
1288
  sftp.connect(config)
@@ -1421,3 +1433,4 @@ Thanks to the following for their contributions -
1421
1433
  - **jhorbulyk:** Contributed posixRename() functionality
1422
1434
  - **teenangst:** Contributed fix for error code 4 in stat() method
1423
1435
  - **kennylbj:** Contributed example of using a throttle stream to limit upload/download bandwidth.
1436
+ - **anton-erofeev:** Documentation fix
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]] and [[https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md][SSH2-STREAMS]] project pages.
11
11
 
12
- Current stable release is *v5.3.1*.
12
+ Current stable release is *v5.3.2*.
13
13
 
14
14
  Code has been tested against Node versions 12.18.2 and 13.14.0
15
15
 
@@ -23,7 +23,23 @@ affect fastput, fastget, put and possibly get operations. Until this issue is
23
23
  resolved and a new version of ssh2/ssh2-streams is released, using node v14 is
24
24
  not recommended.
25
25
 
26
- A bug report hass been logged against the ssh2-streams library as [[https://github.com/mscdex/ssh2-streams/issues/156][issue 156]].
26
+ A bug report hass been logged against the ssh2-streams library as [[https://github.com/mscdex/ssh2-streams/issues/156][issue 156]].
27
+
28
+ _UPDATE_: The author of the upstream ssh2 and ssh2-streams module has decided on
29
+ a re-write of the ssh2 module to address the above issues as well as some other
30
+ design limitations and to allow the module to better fit in with newer versions
31
+ of node. As part of that process, the functionality of ssh2-streams is being
32
+ incorporated into the main ssh2 module and the ssh2-streams module is being
33
+ deprecated. This will require a significant update to this module and may result
34
+ in some API changes, depending on what changes in the re-write of ssh2.
35
+
36
+ To support these changes, a new branch called /version-6/ has been created. This
37
+ branch will use the newest version of ssh2 and for now is very much experimental
38
+ and subject to change.
39
+
40
+ _UPDATE_: Apparently the change in core node which cause the issue with ssh2 has
41
+ been rolled back in node version 15.3.0. Testing seems to indicate the above
42
+ issue does not exist in that version of node.
27
43
 
28
44
  * Installation
29
45
 
@@ -225,7 +241,7 @@ reset to false in preparation for the next error.
225
241
  - Fix bug in checkRemotePath() relating to poor path specifications where
226
242
  you cannot determine parent directory.
227
243
 
228
- ** Version 5.1.1
244
+ ** Version 5.1.1
229
245
  - Bug fix for unexpected close of connections. It would seem that a
230
246
  connections can be unexpectedly closed without an accompanying error event.
231
247
  As methods only looked for error events, the method promise wold never
@@ -240,26 +256,26 @@ reset to false in preparation for the next error.
240
256
  inside promise chains. Common symptom is what appears to be truncated file
241
257
  upload/download. What is really happening is that the end method is being
242
258
  called before the transfer has completed.
243
-
244
- ** Version 5.1.2
259
+
260
+ ** Version 5.1.2
245
261
  - Mainly a bug fix. We needed to add back a global close listener to ensure
246
- the sftp object is unset whenever a close event occurs. As close events can
262
+ the sftp object is unset whenever a close event occurs. As close events can
247
263
  occur outside main method calls, only having method based listeners was not
248
264
  sufficient.
249
265
  - Also added a utils.dumpListeners() method, useful when debugging issues with
250
266
  listener 'leakage' due to failure to remove listeners when no longer required.
251
-
267
+
252
268
  ** Version 5.1.3
253
269
  - Fix issue with permissions for writing to root directory
254
270
  - Cleanup tests to use less connections and eliminate need for test delays
255
- - Bumped some dependencies to latest versions
271
+ - Bumped some dependencies to latest versions
256
272
  ** Version 5.2.0
257
273
  - Add posixRename() method. This is an openssh extension added in openssh
258
274
  v4.8 and will only work on servers which support this extension.conflict
259
275
  - Bumped through2 dependency version to 4.0.2
260
276
 
261
277
  ** Version 5.2.1
262
- - Move some dev dependencies from dependencies to devDependencies.
278
+ - Move some dev dependencies from dependencies to devDependencies.
263
279
  ** Version 5.2.2
264
280
  - Bug fix. Some servers appear to issue errors with code 4 instead of code 2
265
281
  for file not found errors. This version adds checks for error code 4 to the
@@ -285,7 +301,9 @@ reset to false in preparation for the next error.
285
301
  will issue a ~destroy()~ on the underlying stream just before the promise
286
302
  is resolved. The default is ~autoClose: true~ and this default should be
287
303
  used unless there is a known specific reason to change it to false.
288
-
304
+ ** Version 5.3.2
305
+ - Minor README typo fixes
306
+ - Fix error in local file path checks (#294)
289
307
  * Documentation
290
308
 
291
309
  The connection options are the same as those offered by the underlying SSH2
@@ -424,7 +442,7 @@ for that package for an explanation of these values.
424
442
  password: 'borsch', // string Password for password-based user authentication
425
443
  agent: process.env.SSH_AGENT, // string - Path to ssh-agent's UNIX socket
426
444
  privateKey: fs.readFileSync('/path/to/key'), // Buffer or string that contains
427
- passphrase; 'a pass phrase', // string - For an encrypted private key
445
+ passphrase: 'a pass phrase', // string - For an encrypted private key
428
446
  readyTimeout: 20000, // integer How long (in ms) to wait for the SSH handshake
429
447
  strictVendor: true // boolean - Performs a strict server vendor check
430
448
  debug: myDebug // function - Set this to a function that receives a single
@@ -965,7 +983,7 @@ Delete a file on the remote server.
965
983
  Rename a file or directory from ~fromPath~ to ~toPath~. You must have the
966
984
  necessary permissions to modify the remote file.
967
985
 
968
- - fromPath :: string. Path to existing file to be renamed
986
+ - fromPath :: string. Path to existing file to be renamed
969
987
  - toPath :: string. Path to new file existing file is to be renamed to. Should
970
988
  not already exist.
971
989
 
@@ -989,7 +1007,7 @@ necessary permissions to modify the remote file.
989
1007
  #+end_src
990
1008
 
991
1009
  *** posixRename(fromPath, toPath) ==> string
992
-
1010
+
993
1011
  This method uses the openssh POSIX rename extension introduced in OpenSSH 4.8.
994
1012
  The advantage of this version of rename over standard SFTP rename is that it is
995
1013
  an atomic operation and will allow renaming a resource where the destination
@@ -1019,7 +1037,7 @@ protocol and therefore is not supported on all sSFTP servers.
1019
1037
  console.error(err.message);
1020
1038
  });
1021
1039
  #+end_src
1022
-
1040
+
1023
1041
  *** chmod(path, mode) ==> string
1024
1042
 
1025
1043
  Change the mode (read, write or execute permissions) of a remote file or
@@ -1032,7 +1050,7 @@ directory.
1032
1050
 
1033
1051
  #+begin_src javascript
1034
1052
  let path = '/path/to/remote/file.txt';
1035
- let ndwMode = 0o644; // rw-r-r
1053
+ let newMode = 0o644; // rw-r-r
1036
1054
  let client = new Client();
1037
1055
 
1038
1056
  client.connect(config)
@@ -1050,7 +1068,7 @@ directory.
1050
1068
  *** realPath(path) ===> string
1051
1069
 
1052
1070
  Converts a relative path to an absolute path on the remote server. This method
1053
- is mainly used internally to resolve remote path names.
1071
+ is mainly used internally to resolve remote path names.
1054
1072
 
1055
1073
  *Warning*: Currently, there is a platform inconsistency with this method on
1056
1074
  win32 platforms. For servers running on non-win32 platforms, providing a path
@@ -1100,36 +1118,36 @@ using the ~on()~ method.
1100
1118
  require('dotenv').config({path: dotenvPath});
1101
1119
 
1102
1120
  const config = {
1103
- host: process.env.SFTP_SERVER,
1104
- username: process.env.SFTP_USER,
1105
- password: process.env.SFTP_PASSWORD,
1106
- port: process.env.SFTP_PORT || 22
1121
+ host: process.env.SFTP_SERVER,
1122
+ username: process.env.SFTP_USER,
1123
+ password: process.env.SFTP_PASSWORD,
1124
+ port: process.env.SFTP_PORT || 22
1107
1125
  };
1108
1126
 
1109
1127
  async function main() {
1110
- const client = new SftpClient('upload-test');
1111
- const src = path.join(__dirname, '..', 'test', 'testData', 'upload-src');
1112
- const dst = '/home/tim/upload-test';
1113
-
1114
- try {
1115
- await client.connect(config);
1116
- client.on('upload', info => {
1117
- console.log(`Listener: Uploaded ${info.source}`);
1118
- });
1119
- let rslt = await client.uploadDir(src, dst);
1120
- return rslt;
1121
- } finally {
1122
- client.end();
1123
- }
1128
+ const client = new SftpClient('upload-test');
1129
+ const src = path.join(__dirname, '..', 'test', 'testData', 'upload-src');
1130
+ const dst = '/home/tim/upload-test';
1131
+
1132
+ try {
1133
+ await client.connect(config);
1134
+ client.on('upload', info => {
1135
+ console.log(`Listener: Uploaded ${info.source}`);
1136
+ });
1137
+ let rslt = await client.uploadDir(src, dst);
1138
+ return rslt;
1139
+ } finally {
1140
+ client.end();
1141
+ }
1124
1142
  }
1125
1143
 
1126
1144
  main()
1127
- .then(msg => {
1128
- console.log(msg);
1129
- })
1130
- .catch(err => {
1131
- console.log(`main error: ${err.message}`);
1132
- });
1145
+ .then(msg => {
1146
+ console.log(msg);
1147
+ })
1148
+ .catch(err => {
1149
+ console.log(`main error: ${err.message}`);
1150
+ });
1133
1151
 
1134
1152
  #+end_src
1135
1153
 
@@ -1180,7 +1198,7 @@ the ~on()~ method.
1180
1198
  try {
1181
1199
  await client.connect(config);
1182
1200
  client.on('download', info => {
1183
- console.log(`Listener: Download ${info.source}`);
1201
+ console.log(`Listener: Download ${info.source}`);
1184
1202
  });
1185
1203
  let rslt = await client.downloadDir(src, dst);
1186
1204
  return rslt;
@@ -1245,7 +1263,7 @@ Removes the specified listener from the event specified in eventType. Note that
1245
1263
  the ~end()~ method automatically removes all listeners from the client object.
1246
1264
 
1247
1265
  * Platform Quirks & Warnings
1248
- ** Server Capabilities
1266
+ ** Server Capabilities
1249
1267
 
1250
1268
  All SFTP servers and platforms are not equal. Some facilities provided by
1251
1269
  ~ssh2-sfto-client~ either depend on capabilities of the remote server or the
@@ -1352,7 +1370,7 @@ the ~end()~ method automatically removes all listeners from the client object.
1352
1370
  a single connection e.g. upload multiple files, download multiple files etc,
1353
1371
  but after you have called end(), you should not try to re-use the object with
1354
1372
  a further connect() call. Create a new object instead.
1355
-
1373
+
1356
1374
  * FAQ
1357
1375
 
1358
1376
  ** Remote server drops connections with only an end event
@@ -1532,7 +1550,7 @@ issue.
1532
1550
  data, you can use a stream to limit throughput. The following example was
1533
1551
  provided by /kennylbj/. Note that there is a caveat that we must set the
1534
1552
  ~autoClose~ flag to false to avoid calling an extra ~_read()~ on a closed stream
1535
- that may cause _get Permission Denied error in ssh2-streams.
1553
+ that may cause _get Permission Denied error in ssh2-streams.
1536
1554
 
1537
1555
 
1538
1556
  #+begin_src javascript
@@ -1618,7 +1636,7 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1618
1636
  There are some common errors people tend to make when using Promises or
1619
1637
  Asyc/Await. These are by far the most common problem found in issues logged
1620
1638
  against this module. Please check for some of these before logging your
1621
- issue.
1639
+ issue.
1622
1640
 
1623
1641
  *** Not returning the promise in a ~then()~ block
1624
1642
 
@@ -1628,9 +1646,9 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1628
1646
  generates. Failing to do this will result in the ~then()~ block completing
1629
1647
  and your code starting execution of the next ~then()~, ~catch()~ or
1630
1648
  ~finally()~ block before your promise has been fulfilled. For exmaple, the
1631
- following will not do what you expect
1649
+ following will not do what you expect
1632
1650
 
1633
- #+begin_src javascript
1651
+ #+begin_src javascript
1634
1652
  sftp.connect(config)
1635
1653
  .then(() => {
1636
1654
  sftp.fastGet('foo.txt', 'bar.txt');
@@ -1641,14 +1659,14 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1641
1659
  console.error(e.message);
1642
1660
  });
1643
1661
  #+end_src
1644
-
1662
+
1645
1663
  In the above code, the ~sftp.end()~ method will almost certainly be called
1646
- before ~sftp.gastGet()~ has been fulfilled (unless the /foo.txt/ file is
1664
+ before ~sftp.fastGet()~ has been fulfilled (unless the /foo.txt/ file is
1647
1665
  really small!). In fact, the whole promise chain will complete and exit even
1648
1666
  before the ~sftp.end()~ call has been fulfilled. The correct code would be
1649
- something like
1650
-
1651
- #+begin_src javascript
1667
+ something like
1668
+
1669
+ #+begin_src javascript
1652
1670
  sftp.connect(config)
1653
1671
  .then(() => {
1654
1672
  return sftp.fastGet('foo.txt', 'bar.txt');
@@ -1659,20 +1677,20 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1659
1677
  console.error(e.message);
1660
1678
  });
1661
1679
  #+end_src
1662
-
1680
+
1663
1681
  Note the ~return~ statements. These ensure that the Promise returned by the
1664
1682
  client method is returned into the promise chain. It will be this promise
1665
1683
  the next block in the chain will wait on to be fulfilled before the next
1666
1684
  block is executed. Without the return statement, that block will return the
1667
1685
  default promise for that block, which essentially says /this block has been
1668
1686
  fulfilled/. What you really want is the promise which says /your sftp client
1669
- method call has been fulfilled/.
1687
+ method call has been fulfilled/.
1670
1688
 
1671
1689
  A common symptom of this type of error is for file uploads or download to
1672
1690
  fail to complete or for data in those files to be truncated. What is
1673
1691
  happening is that the connection is being ended before the transfer has
1674
- completed.
1675
-
1692
+ completed.
1693
+
1676
1694
  *** Mixing Promise Chains and Async/Await
1677
1695
 
1678
1696
  Another common error is to mix Promise chains and async/await calls. This is
@@ -1706,14 +1724,14 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1706
1724
  returning is a fulfilled promise which says the ~then()~ block has been run
1707
1725
  (note that the await'ed promise is not being returned and is therefore
1708
1726
  outside the main Promise chain). As a result, the ~finally()~ block will be
1709
- executed before the await promise has been fulfilled.
1727
+ executed before the await promise has been fulfilled.
1710
1728
 
1711
1729
  Using async/await inside the promise chain has created unnecessary
1712
1730
  complexity and leads to incorrect assumptions regarding how the code will
1713
1731
  execute. A quick glance at the code is likely to give the impression that
1714
1732
  execution will wait for the ~sftp.fastGet()~ call to be fulfilled before
1715
1733
  continuing. This is not the case. The code would be more clearly expressed
1716
- as either
1734
+ as either
1717
1735
 
1718
1736
  #+begin_src javascript
1719
1737
  sftp.connect(config)
@@ -1728,7 +1746,7 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1728
1746
  return sftp.end();
1729
1747
  });
1730
1748
  #+end_src
1731
-
1749
+
1732
1750
  *or, using async/await*
1733
1751
 
1734
1752
  #+begin_src javascript
@@ -1752,14 +1770,14 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1752
1770
  signals, such as an error event. In general, you cannot use try/catch blocks
1753
1771
  for asynchronous code and expect errors to be caught by the ~catch~ block.
1754
1772
  Handling errors in asynchronous code is one of the key reasons we now have
1755
- the Promise and async/await frameworks.
1773
+ the Promise and async/await frameworks.
1756
1774
 
1757
1775
  The basic problem is that the try/catch block will have completed execution
1758
1776
  before the asynchronous code has completed. If the asynchronous code has not
1759
1777
  compleed, then there is a potential for it to raise an error. However, as
1760
1778
  the try/catch block has already completed, there is no /catch/ waiting to
1761
1779
  catch the error. It will bubble up and probably result in your script
1762
- exiting with an uncaught exception error.
1780
+ exiting with an uncaught exception error.
1763
1781
 
1764
1782
  Error events are essentially asynchronous code. You don't know when such
1765
1783
  events will fire. Therefore, you cannot use a try/catch block to catch such
@@ -1770,8 +1788,8 @@ trying to determine if the issue is with the underlying ~ssh2~ and
1770
1788
  error exceptions that cause your script to exit abnormally despite having
1771
1789
  try/catch blocks in your script. What you need to do is look at your code
1772
1790
  and find where errors are raised asynchronously and use an event handler or
1773
- some other mechanism to manage any errors raised.
1774
-
1791
+ some other mechanism to manage any errors raised.
1792
+
1775
1793
  ** Debugging Support
1776
1794
 
1777
1795
  You can add a ~debug~ property to the config object passed in to ~connect()~ to
@@ -1864,3 +1882,4 @@ Thanks to the following for their contributions -
1864
1882
  - teenangst :: Contributed fix for error code 4 in stat() method
1865
1883
  - kennylbj :: Contributed example of using a throttle stream to limit
1866
1884
  upload/download bandwidth.
1885
+ - anton-erofeev :: Documentation fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh2-sftp-client",
3
- "version": "5.3.1",
3
+ "version": "5.3.2",
4
4
  "description": "ssh2 sftp client for node",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "checksum": "^0.1.1",
33
33
  "dotenv": "^8.2.0",
34
34
  "mocha": "^8.1.3",
35
- "moment": "^2.27.0",
35
+ "moment": "^2.29.0",
36
36
  "through2": "^4.0.2"
37
37
  }
38
38
  }
package/src/index.js CHANGED
@@ -598,9 +598,9 @@ class SftpClient {
598
598
  this.debugMsg('fastGet local path info ', localInfo);
599
599
  if (!localInfo.valid) {
600
600
  let e = utils.formatError(
601
- localInfo.parentMsg,
601
+ localInfo.msg,
602
602
  'fastGet',
603
- localInfo.parentCode
603
+ localInfo.code
604
604
  );
605
605
  throw e;
606
606
  }
package/src/utils.js CHANGED
@@ -131,7 +131,7 @@ function makeCloseListener(client, reject, name) {
131
131
  return function () {
132
132
  if (!client.endCalled) {
133
133
  if (reject) {
134
- reject(formatError('Connection closed unepectedly', name));
134
+ reject(formatError('Connection closed unexpectedly', name));
135
135
  } else {
136
136
  console.error(`${client.clientName}: Connection closed unexpectedly`);
137
137
  }