ssh2-sftp-client 6.0.1 → 7.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/CHANGELOG.org +8 -1
- package/README.md +90 -106
- package/README.org +64 -93
- package/package.json +8 -7
- package/src/index.js +218 -203
- package/src/utils.js +41 -15
package/README.org
CHANGED
|
@@ -7,40 +7,14 @@ an SFTP client for node.js, a wrapper around [[https://github.com/mscdex/ssh2][S
|
|
|
7
7
|
convenience abstraction as well as a Promise based API.
|
|
8
8
|
|
|
9
9
|
Documentation on the methods and available options in the underlying modules can
|
|
10
|
-
be found on the [[https://github.com/mscdex/ssh2][SSH2]]
|
|
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 *v7.0.0*.
|
|
13
13
|
|
|
14
|
-
Code has been tested against Node versions 12.
|
|
14
|
+
Code has been tested against Node versions 12.22.1, 14.17.0 and 16.2.0
|
|
15
15
|
|
|
16
16
|
Node versions < 10.x are not supported.
|
|
17
17
|
|
|
18
|
-
_WARNING_ There is currently a regression error with versions of node later than
|
|
19
|
-
version 14.0. It appears that when using streams with chunk sizes which exceed
|
|
20
|
-
the high water mark for the stream, a drain event is no longer emitted. As a
|
|
21
|
-
result, streams with sufficient data will hang indefinitely. This appears to
|
|
22
|
-
affect fastput, fastget, put and possibly get operations. Until this issue is
|
|
23
|
-
resolved and a new version of ssh2/ssh2-streams is released, using node v14 is
|
|
24
|
-
not recommended.
|
|
25
|
-
|
|
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.
|
|
43
|
-
|
|
44
18
|
* Installation
|
|
45
19
|
|
|
46
20
|
#+begin_src shell
|
|
@@ -67,47 +41,31 @@ npm install ssh2-sftp-client
|
|
|
67
41
|
});
|
|
68
42
|
#+end_src
|
|
69
43
|
|
|
70
|
-
* Version
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
- Replace the ~retry~ library module with the ~promise-retry~ library module.
|
|
96
|
-
This module also uses the ~retry~ library, but at a higher level abstracted
|
|
97
|
-
for use with Promises. As a result, the number of failed retries is no longer
|
|
98
|
-
returned as part of the error message when all attempted connection retries
|
|
99
|
-
fail.
|
|
100
|
-
- Reduced argument verification code. Version 5.x added a lot of additional
|
|
101
|
-
argument verification code in an attempt to provide more meaningful error
|
|
102
|
-
messages. While this goal was achieved, it did have a significant performance
|
|
103
|
-
impact, especially with respect to small file transfers. This additional
|
|
104
|
-
argument verification has now been removed in favour of faster code. The
|
|
105
|
-
downside is that some error messages have changed and in some cases, will not
|
|
106
|
-
be as meaningful or will be more generic in nature. This seems as a reasonable
|
|
107
|
-
compromise. It may result in increased difficulty tracking down why a script
|
|
108
|
-
is failing, but once a script is working, it should be more efficient. If your
|
|
109
|
-
code relies on the text in error messages, you will need to verify whether the
|
|
110
|
-
text is still the same in any testing and adjust where necessary.
|
|
44
|
+
* Version 7.x Changes
|
|
45
|
+
|
|
46
|
+
- This version is based on version 1.1.0 of ~ssh2~. This version of ~ssh2~ is a
|
|
47
|
+
complete re-write of the ~ssh2~ library. This re-write addresses issues
|
|
48
|
+
encountered when using node v14 as well as some design weaknesses in the
|
|
49
|
+
previous 0.8.x version.
|
|
50
|
+
|
|
51
|
+
- *Breaking Change* Expanded option handling for ~get()~ and ~put()~ methods. A number of use
|
|
52
|
+
cases were identified where setting specific options on the read and write
|
|
53
|
+
streams and the pipe operation are necessary. For example, disabling
|
|
54
|
+
~autoClose~ on streams or the ~end~ event in pipes. The ~options~ argument for
|
|
55
|
+
~get()~ and ~put()~ calls now supports properties for ~readStreamOptions~,
|
|
56
|
+
~writeStreamOptions~ and ~pipeOptions~. Note that options are only applied to
|
|
57
|
+
streams created by the ~get()~ and ~put()~ methods. Streams passed into these
|
|
58
|
+
methods are under the control of the client code and therefore cannot have
|
|
59
|
+
options supplied in arguments to those streams (you would apply such options
|
|
60
|
+
when you create the streams). Options are typically only necessary in special
|
|
61
|
+
use cases. Most of the time, no options are required. However, if you are
|
|
62
|
+
currently using options to either ~put()~ or ~get()~, you will need to update
|
|
63
|
+
your code to map these options to the new structure.
|
|
64
|
+
|
|
65
|
+
- Improved event handling. A listener for a global error event is now defined to
|
|
66
|
+
catch errors which occur in-between method calls i.e. connection lost
|
|
67
|
+
in-between calls to the library methods. A new mechanism has also been added
|
|
68
|
+
for removal of listeners when no longer required.
|
|
111
69
|
|
|
112
70
|
* Documentation
|
|
113
71
|
|
|
@@ -120,10 +78,10 @@ All the methods will return a Promise, except for ~on()~ and
|
|
|
120
78
|
** Specifying Paths
|
|
121
79
|
|
|
122
80
|
The convention with both FTP and SFTP is that paths are specified using a
|
|
123
|
-
'nix' style i.e. use
|
|
124
|
-
SFTP server is running on a win32 platform, you should use
|
|
125
|
-
as the path separator. For example, for a win32 path of
|
|
126
|
-
would actually use
|
|
81
|
+
'nix' style i.e. use ~/~ as the path separator. This means that even if your
|
|
82
|
+
SFTP server is running on a win32 platform, you should use ~/~ instead of ~\~
|
|
83
|
+
as the path separator. For example, for a win32 path of ~C:\Users\fred~ you
|
|
84
|
+
would actually use ~/C:/Users/fred~. If your win32 server does not support
|
|
127
85
|
the 'nix' path convention, you can try setting the ~remotePathSep~ property
|
|
128
86
|
of the ~SftpClient~ object to the path separator of your remote server. This
|
|
129
87
|
*might* work, but has not been tested. Please let me know if you need to do
|
|
@@ -466,22 +424,30 @@ better off using the ~fastGet()~ method.
|
|
|
466
424
|
|
|
467
425
|
**** Options
|
|
468
426
|
|
|
469
|
-
The options
|
|
470
|
-
|
|
427
|
+
The ~options~ argument can be used to pass options to the underlying streams and
|
|
428
|
+
pipe call used by this method. The argument is an object with three possible
|
|
429
|
+
properties, ~readStreamOptions~, ~writeStreamOptions~ and ~pipeOptions~. The
|
|
430
|
+
values for each of these properties should be an object containing the required
|
|
431
|
+
options. For example, possible read stream and pipe options could be defined as
|
|
471
432
|
|
|
472
433
|
#+begin_src javascript
|
|
473
|
-
{
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
434
|
+
let options = {
|
|
435
|
+
readStreamOptions: {
|
|
436
|
+
flags: 'r',
|
|
437
|
+
encoding: null,
|
|
438
|
+
handle: null,
|
|
439
|
+
mode: 0o666,
|
|
440
|
+
autoClose: true
|
|
441
|
+
},
|
|
442
|
+
pipeOptions: {
|
|
443
|
+
end: false
|
|
444
|
+
}};
|
|
445
|
+
|
|
480
446
|
#+end_src
|
|
481
447
|
|
|
482
448
|
Most of the time, you won't want to use any options. Sometimes, it may be useful
|
|
483
449
|
to set the encoding. For example, to 'utf-8'. However, it is important not to do
|
|
484
|
-
this for binary files to avoid data corruption.
|
|
450
|
+
this for binary files to avoid data corruption.
|
|
485
451
|
|
|
486
452
|
**** Example Use
|
|
487
453
|
|
|
@@ -563,20 +529,25 @@ stream are piped to the ~remotePath~ on the server.
|
|
|
563
529
|
- src :: string | buffer | readable stream. Data source for data to copy to the
|
|
564
530
|
remote server.
|
|
565
531
|
- remotePath :: string. Path to the remote file to be created on the server.
|
|
566
|
-
- options :: object. Options which can be passed to adjust the write stream used
|
|
567
|
-
in sending the data to the remote server
|
|
532
|
+
- options :: object. Options which can be passed to adjust the read and write stream used
|
|
533
|
+
in sending the data to the remote server or the pipe call used to
|
|
534
|
+
make the data transfer (see below).
|
|
568
535
|
|
|
569
536
|
**** Options
|
|
570
537
|
|
|
571
|
-
The
|
|
538
|
+
The options object supports three properties, ~readStreamOptions~,
|
|
539
|
+
~writeStreamOptions~ and ~pipeOptions~. The value for each property should be an
|
|
540
|
+
object with options as properties and their associated values representing the
|
|
541
|
+
option value. For example, you might use the following to set ~writeStream~ options.
|
|
572
542
|
|
|
573
543
|
#+begin_src javascript
|
|
574
544
|
{
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
545
|
+
writeStreamOptions: {
|
|
546
|
+
flags: 'w', // w - write and a - append
|
|
547
|
+
encoding: null, // use null for binary files
|
|
548
|
+
mode: 0o666, // mode to use for created file (rwx)
|
|
549
|
+
autoClose: true // automatically close the write stream when finished
|
|
550
|
+
}}
|
|
580
551
|
#+end_src
|
|
581
552
|
|
|
582
553
|
The most common options to use are mode and encoding. The values shown above are
|
|
@@ -1084,7 +1055,7 @@ the ~end()~ method automatically removes all listeners from the client object.
|
|
|
1084
1055
|
** Server Capabilities
|
|
1085
1056
|
|
|
1086
1057
|
All SFTP servers and platforms are not equal. Some facilities provided by
|
|
1087
|
-
~ssh2-
|
|
1058
|
+
~ssh2-sftp-client~ either depend on capabilities of the remote server or the
|
|
1088
1059
|
underlying capabilities of the remote server platform. As an example,
|
|
1089
1060
|
consider ~chmod()~. This command depends on a remote filesystem which
|
|
1090
1061
|
implements the 'nix' concept of users and groups. The /win32/ platform does
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2-sftp-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "ssh2 sftp client for node",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"keywords": ["sftp", "nodejs", "promises"],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "mocha",
|
|
13
|
-
"coverage": "nyc npm run test"
|
|
13
|
+
"coverage": "nyc npm run test",
|
|
14
|
+
"lint": "eslint \"src/**/*.js\" --quiet"
|
|
14
15
|
},
|
|
15
16
|
"author": "Tim Cross",
|
|
16
17
|
"email": "theophilusx@gmail.com",
|
|
@@ -24,18 +25,18 @@
|
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"concat-stream": "^2.0.0",
|
|
26
27
|
"promise-retry": "^2.0.1",
|
|
27
|
-
"ssh2": "^
|
|
28
|
-
"winston": "^3.3.3"
|
|
28
|
+
"ssh2": "^1.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"chai": "^4.2.0",
|
|
32
32
|
"chai-as-promised": "^7.1.1",
|
|
33
33
|
"chai-subset": "^1.6.0",
|
|
34
34
|
"checksum": "^0.1.1",
|
|
35
|
-
"dotenv": "^
|
|
36
|
-
"mocha": "^
|
|
35
|
+
"dotenv": "^10.0.0",
|
|
36
|
+
"mocha": "^9.0.0",
|
|
37
37
|
"moment": "^2.29.1",
|
|
38
38
|
"nyc": "^15.1.0",
|
|
39
|
-
"through2": "^4.0.2"
|
|
39
|
+
"through2": "^4.0.2",
|
|
40
|
+
"winston": "^3.3.3"
|
|
40
41
|
}
|
|
41
42
|
}
|