ssh2-sftp-client 7.0.0 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -14
- package/README.org +115 -62
- package/package.json +20 -6
- package/src/constants.js +3 -5
- package/src/index.js +412 -311
- package/src/utils.js +161 -51
- package/CHANGELOG.org +0 -232
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
- [Specifying Paths](#sec-5-1)
|
|
7
7
|
- [Methods](#sec-5-2)
|
|
8
8
|
- [new SftpClient(name) ===> SFTP client object](#sec-5-2-1)
|
|
9
|
-
- [connect(config) ===>
|
|
9
|
+
- [connect(config) ===> SFTP object](#sec-5-2-2)
|
|
10
10
|
- [list(path, pattern) ==> Array[object]](#sec-5-2-3)
|
|
11
11
|
- [exists(path) ==> boolean](#sec-5-2-4)
|
|
12
12
|
- [stat(path) ==> object](#sec-5-2-5)
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
- [Add and Remove Listeners](#sec-5-2-22)
|
|
30
30
|
- [Platform Quirks & Warnings](#sec-6)
|
|
31
31
|
- [Server Capabilities](#sec-6-1)
|
|
32
|
-
- [Promises &
|
|
32
|
+
- [Promises, Events & Managing Exceptions](#sec-6-2)
|
|
33
|
+
- [Adding Custom Handlers](#sec-6-2-1)
|
|
33
34
|
- [Windows Based Servers](#sec-6-3)
|
|
34
35
|
- [Don't Re-use SftpClient Objects](#sec-6-4)
|
|
35
36
|
- [FAQ](#sec-7)
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
- [How can I connect through a Socks Proxy](#sec-7-4)
|
|
40
41
|
- [Timeout while waiting for handshake or handshake errors](#sec-7-5)
|
|
41
42
|
- [How can I limit upload/download speed](#sec-7-6)
|
|
43
|
+
- [Connection hangs or fails for larger files](#sec-7-7)
|
|
42
44
|
- [Examples](#sec-8)
|
|
43
45
|
- [Troubleshooting](#sec-9)
|
|
44
46
|
- [Common Errors](#sec-9-1)
|
|
@@ -59,7 +61,7 @@ an SFTP client for node.js, a wrapper around [SSH2](https://github.com/mscdex/ss
|
|
|
59
61
|
|
|
60
62
|
Documentation on the methods and available options in the underlying modules can be found on the [SSH2](https://github.com/mscdex/ssh2) project pages.
|
|
61
63
|
|
|
62
|
-
Current stable release is **v7.0.
|
|
64
|
+
Current stable release is **v7.0.4**.
|
|
63
65
|
|
|
64
66
|
Code has been tested against Node versions 12.22.1, 14.17.0 and 16.2.0
|
|
65
67
|
|
|
@@ -93,7 +95,7 @@ sftp.connect({
|
|
|
93
95
|
|
|
94
96
|
# Version 7.x Changes<a id="sec-4"></a>
|
|
95
97
|
|
|
96
|
-
- This version is based on version 1.
|
|
98
|
+
- This version is based on version 1.x.x of `ssh2`. This version of `ssh2` is a complete re-write of the `ssh2` library. This re-write addresses issues encountered when using node v14 as well as some design weaknesses in the previous 0.8.x version.
|
|
97
99
|
|
|
98
100
|
- **Breaking Change** Expanded option handling for `get()` and `put()` methods. A number of use cases were identified where setting specific options on the read and write streams and the pipe operation are necessary. For example, disabling `autoClose` on streams or the `end` event in pipes. The `options` argument for `get()` and `put()` calls now supports properties for `readStreamOptions`, `writeStreamOptions` and `pipeOptions`. Note that options are only applied to streams created by the `get()` and `put()` methods. Streams passed into these methods are under the control of the client code and therefore cannot have options supplied in arguments to those streams (you would apply such options when you create the streams). Options are typically only necessary in special use cases. Most of the time, no options are required. However, if you are currently using options to either `put()` or `get()`, you will need to update your code to map these options to the new structure.
|
|
99
101
|
|
|
@@ -173,7 +175,7 @@ Constructor to create a new `ssh2-sftp-client` object. An optional `name` string
|
|
|
173
175
|
});
|
|
174
176
|
```
|
|
175
177
|
|
|
176
|
-
### connect(config) ===>
|
|
178
|
+
### connect(config) ===> SFTP object<a id="sec-5-2-2"></a>
|
|
177
179
|
|
|
178
180
|
Connect to an sftp server. Full documentation for connection options is available [here](https://github.com/mscdex/ssh2#user-content-client-methods)
|
|
179
181
|
|
|
@@ -918,11 +920,13 @@ Although normally not required, you can add and remove custom listeners on the s
|
|
|
918
920
|
|
|
919
921
|
- **error:** An error occurred. Calls listener with an error argument.
|
|
920
922
|
- **end:** The socket has been disconnected. No argument.
|
|
921
|
-
- **close:** The socket was closed.
|
|
923
|
+
- **close:** The socket was closed.
|
|
922
924
|
|
|
923
925
|
1. on(eventType, listener)
|
|
924
926
|
|
|
925
|
-
Adds the specified listener to the specified event type. It the event type is `error`, the listener should accept 1 argument, which will be an Error object.
|
|
927
|
+
Adds the specified listener to the specified event type. It the event type is `error`, the listener should accept 1 argument, which will be an Error object. The event handlers for `end` and `close` events have no arguments.
|
|
928
|
+
|
|
929
|
+
The handlers will be added to the beginning of the listener's event handlers, so it will be called before any of the `ssh2-sftp-client` listeners.
|
|
926
930
|
|
|
927
931
|
2. removeListener(eventType, listener)
|
|
928
932
|
|
|
@@ -936,19 +940,25 @@ All SFTP servers and platforms are not equal. Some facilities provided by `ssh2-
|
|
|
936
940
|
|
|
937
941
|
One way to determine whether an issue you are encountering is due to `ssh2-sftp-client` or due to the remote server or server platform is to use a simple CLI sftp program, such as openSSH's sftp command. If you observe the same behaviour using plain `sftp` on the command line, the issue is likely due to server or remote platform limitations. Note that you should not use a GUI sftp client, like `Filezilla` or `winSCP` as such GUI programs often attempt to hide these server and platform incompatibilities and will take additional steps to simulate missing functionality etc. You want to use a CLI program which does as little as possible.
|
|
938
942
|
|
|
939
|
-
|
|
943
|
+
## Promises, Events & Managing Exceptions<a id="sec-6-2"></a>
|
|
944
|
+
|
|
945
|
+
One of the challenges in providing a Promise based API over a module like SSH2, which is event based is how to ensure events are handled appropriately. The challenge is due to the synchronous nature of events. You cannot use `try/catch` for events because you have no way of knowing when the event might fire. For example, it could easily fire after your `try/catch` block as completed execution.
|
|
946
|
+
|
|
947
|
+
Things become even more complicated once you mix in Promises. When you define a promise, you have to methods which can be called to fulfil a promise, `resolve` and `reject`. Only one can be called - once you call `resolve`, you cannot call `reject` (well, you can call it, but it won't have any impact on the fulfilment status of the promise). The problem arises when an event, for exmaple an `error` event is fired either after you have resolved a promise or possibly in-between promises. If you don't catch the `error` event, your script will likely crash with an `uncaught exception` error.
|
|
940
948
|
|
|
941
|
-
|
|
949
|
+
To make matters worse, some servers, particularly servers running on a Windows platform, will raise multiple errors for the same error *event*. For example, when you attempt to connect with a bad username or password, you will get a `All authentication methods have failed` exception. However, under Windows, you will also get a `Connection reset by peer` exception. If we reject the connect promise based on the authentication failure exception, what do we do with the `reset by peer` exception? More critically, what will handle that exception given the promise has already been fulfilled and completed? To make matters worse, it seems that Windows based servers also raise an error event for *non-errors*. For example, when you call the `end()` method, the connection is closed. On windows, this also results in a *connection reset by peer* error. While it could be argued that the remote server resetting the connection after receiving a disconnect request is not an error, it doesn't change the fact that one is raised and we need to somehow deal with it.
|
|
942
950
|
|
|
943
|
-
|
|
951
|
+
To handle this, `ssh2-sftp-client` implements a couple of strategies. Firstly, when you call one of the module's methods, it adds `error`, `end` and `close` event listeners which will call the `reject` moethod on the enclosing promise. It also keeps track of whether an error has been handled and if it has, it ignores any subsequent errors until the promise ends. Typically, the first error caught has the most relevant information and any subsequent error events are less critical or informative, so ignoring them has no negative impact. Provided one of the events is raised before the promise is fulfilled, these handlers will consume the event and deal with it appropriately.
|
|
944
952
|
|
|
945
|
-
|
|
953
|
+
In testing, it was found that in some situations, particularly during connect operations, subsequent errors fired with a small delay. This prevents the errors from being handled by the event handlers associated with the connect promise. To deal with this, a small 500ms delay has been added to the connect() method, which effectively delays the removal of the event handlers until all events have been caught.
|
|
946
954
|
|
|
947
|
-
|
|
955
|
+
The other area where additional events are fired is during the end() call. To deal with these events, the `end()` method setus up listeners which will simply ignore additional `error`, `end` and `close` events. It is assumed that once you have called `end()` you really only care about any main error which occurs and no longer care about other errors that may be raised as the connection is terminated.
|
|
948
956
|
|
|
949
|
-
|
|
957
|
+
In addition to the promise based event handlers, `ssh2-sftp-client` also implements global event handlers which will catch any `error`, `end` or `close` events. Essentially, these global handlers only reset the `sftp` property of the client object, effectively ensuring any subsequent calls are rejected and in the case of an error, send the error to the console.
|
|
950
958
|
|
|
951
|
-
|
|
959
|
+
### Adding Custom Handlers<a id="sec-6-2-1"></a>
|
|
960
|
+
|
|
961
|
+
While the above strategies appear to work for the majority of use cases, there are always going to be edge cases which require more flexible or powerful event handling. To support this, the `on()` and `removeListener()` methods are provided. Any event listener added using the `on()` method will be added at the beginning of the list of handlers for that event, ensuring it will be called before any global or promise local events. See the documentation for the `on()` method for details.
|
|
952
962
|
|
|
953
963
|
## Windows Based Servers<a id="sec-6-3"></a>
|
|
954
964
|
|
|
@@ -1097,6 +1107,8 @@ client.connect({
|
|
|
1097
1107
|
|
|
1098
1108
|
Some users have encountered the error 'Timeout while waiting for handshake' or 'Handshake failed, no matching client->server ciphers. This is often due to the client not having the correct configuration for the transport layer algorithms used by ssh2. One of the connect options provided by the ssh2 module is `algorithm`, which is an object that allows you to explicitly set the key exchange, ciphers, hmac and compression algorithms as well as server host key used to establish the initial secure connection. See the SSH2 documentation for details. Getting these parameters correct usually resolves the issue.
|
|
1099
1109
|
|
|
1110
|
+
When encountering this type of problem, one worthwhile approach is to use openSSH's CLI sftp program with the `-v` switch to raise loggin levels. This will show you what algorithms the CLI is using. You can then use this information to match the names with the accepted algorithm names documented in the `ssh2` README to set the properties in the `algorithms` object.
|
|
1111
|
+
|
|
1100
1112
|
## How can I limit upload/download speed<a id="sec-7-6"></a>
|
|
1101
1113
|
|
|
1102
1114
|
If you want to limit the amount of bandwidth used during upload/download of data, you can use a stream to limit throughput. The following example was provided by *kennylbj*. Note that there is a caveat that we must set the `autoClose` flag to false to avoid calling an extra `_read()` on a closed stream that may cause \_get Permission Denied error in ssh2-streams.
|
|
@@ -1134,6 +1146,14 @@ try {
|
|
|
1134
1146
|
}
|
|
1135
1147
|
```
|
|
1136
1148
|
|
|
1149
|
+
## Connection hangs or fails for larger files<a id="sec-7-7"></a>
|
|
1150
|
+
|
|
1151
|
+
This was contributed by Ladislav Jacho. Thanks.
|
|
1152
|
+
|
|
1153
|
+
A symptom of this issue is that you are able to upload small files, but uploading larger ones fail. You probably have an MTU/fragmentation problem. For each network interface on both client and server set the MTU to 576, e.g. `ifconfig eth0 mtu 576`. If that works, you need to find the largest MTU which will work for your network. An MTU which is too small will adversely affect throughput speed. A common value to use is an MTU of 1400.
|
|
1154
|
+
|
|
1155
|
+
For more explanation, see [issue #342](https://github.com/theophilusx/ssh2-sftp-client/issues/342).
|
|
1156
|
+
|
|
1137
1157
|
# Examples<a id="sec-8"></a>
|
|
1138
1158
|
|
|
1139
1159
|
I have started collecting example scripts in the example directory of the repository. These are mainly scripts I have put together in order to investigate issues or provide samples for users. They are not robust, lack adequate error handling and may contain errors. However, I think they are still useful for helping developers see how the module and API can be used.
|
|
@@ -1311,6 +1331,8 @@ Perhaps the best assistance is a minimal reproducible example of the issue. Once
|
|
|
1311
1331
|
|
|
1312
1332
|
Pull requests are always welcomed. However, please ensure your changes pass all tests and if your adding a new feature, that tests for that feature are included. Likewise, for new features or enhancements, please include any relevant documentation updates.
|
|
1313
1333
|
|
|
1334
|
+
**Note**: The `README.md` file is generated from the `README.org` file. Therefore, any documentation updates or fixes need to be made to the `README.org` file. This file is *tangled* using `Emacs` org mode. If you don't use Emacs or org-mode, don't be too concerned. The org-mode syntax is straight-forward and similar to *markdown*. I will verify any updates to `README.org` and generate a new `README.md` when necessary. The main point to note is that any changes made directly to `README.md` will not persist and will be lost when a new version is generated, so don't modify that file.
|
|
1335
|
+
|
|
1314
1336
|
This module will adopt a standard semantic versioning policy. Please indicate in your pull request what level of change it represents i.e.
|
|
1315
1337
|
|
|
1316
1338
|
- **Major:** Change to API or major change in functionality which will require an increase in major version number.
|
|
@@ -1332,3 +1354,5 @@ Thanks to the following for their contributions -
|
|
|
1332
1354
|
- **teenangst:** Contributed fix for error code 4 in stat() method
|
|
1333
1355
|
- **kennylbj:** Contributed example of using a throttle stream to limit upload/download bandwidth.
|
|
1334
1356
|
- **anton-erofeev:** Documentation fix
|
|
1357
|
+
- **Ladislav Jacho:** Contributed solution explanation for connections hanging when transferring larger files.
|
|
1358
|
+
- **Emma Milner:** Contributed fix for put() bug
|
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 *v7.0.
|
|
12
|
+
Current stable release is *v7.0.4*.
|
|
13
13
|
|
|
14
14
|
Code has been tested against Node versions 12.22.1, 14.17.0 and 16.2.0
|
|
15
15
|
|
|
@@ -43,7 +43,7 @@ npm install ssh2-sftp-client
|
|
|
43
43
|
|
|
44
44
|
* Version 7.x Changes
|
|
45
45
|
|
|
46
|
-
- This version is based on version 1.
|
|
46
|
+
- This version is based on version 1.x.x of ~ssh2~. This version of ~ssh2~ is a
|
|
47
47
|
complete re-write of the ~ssh2~ library. This re-write addresses issues
|
|
48
48
|
encountered when using node v14 as well as some design weaknesses in the
|
|
49
49
|
previous 0.8.x version.
|
|
@@ -175,7 +175,7 @@ client has thrown the error.
|
|
|
175
175
|
});
|
|
176
176
|
#+end_src
|
|
177
177
|
|
|
178
|
-
*** connect(config) ===>
|
|
178
|
+
*** connect(config) ===> SFTP object
|
|
179
179
|
|
|
180
180
|
Connect to an sftp server. Full documentation for connection options is
|
|
181
181
|
available [[https://github.com/mscdex/ssh2#user-content-client-methods][here]]
|
|
@@ -1036,15 +1036,16 @@ them have any meaning in the context of SFTP. These are
|
|
|
1036
1036
|
|
|
1037
1037
|
- error :: An error occurred. Calls listener with an error argument.
|
|
1038
1038
|
- end :: The socket has been disconnected. No argument.
|
|
1039
|
-
- close :: The socket was closed.
|
|
1040
|
-
was closed due to errors.
|
|
1039
|
+
- close :: The socket was closed.
|
|
1041
1040
|
|
|
1042
1041
|
**** on(eventType, listener)
|
|
1043
1042
|
|
|
1044
1043
|
Adds the specified listener to the specified event type. It the event type is
|
|
1045
|
-
~error~, the listener should accept 1 argument, which will be an Error object.
|
|
1046
|
-
|
|
1047
|
-
|
|
1044
|
+
~error~, the listener should accept 1 argument, which will be an Error object.
|
|
1045
|
+
The event handlers for =end= and =close= events have no arguments.
|
|
1046
|
+
|
|
1047
|
+
The handlers will be added to the beginning of the listener's event handlers, so
|
|
1048
|
+
it will be called before any of the =ssh2-sftp-client= listeners.
|
|
1048
1049
|
|
|
1049
1050
|
**** removeListener(eventType, listener)
|
|
1050
1051
|
|
|
@@ -1072,60 +1073,81 @@ the ~end()~ method automatically removes all listeners from the client object.
|
|
|
1072
1073
|
additional steps to simulate missing functionality etc. You want to use a CLI
|
|
1073
1074
|
program which does as little as possible.
|
|
1074
1075
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
due to
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1076
|
+
** Promises, Events & Managing Exceptions
|
|
1077
|
+
|
|
1078
|
+
One of the challenges in providing a Promise based API over a module like
|
|
1079
|
+
SSH2, which is event based is how to ensure events are handled appropriately.
|
|
1080
|
+
The challenge is due to the synchronous nature of events. You cannot use
|
|
1081
|
+
=try/catch= for events because you have no way of knowing when the event
|
|
1082
|
+
might fire. For example, it could easily fire after your =try/catch= block as
|
|
1083
|
+
completed execution.
|
|
1084
|
+
|
|
1085
|
+
Things become even more complicated once you mix in Promises. When you define
|
|
1086
|
+
a promise, you have to methods which can be called to fulfil a promise,
|
|
1087
|
+
=resolve= and =reject=. Only one can be called - once you call =resolve=, you
|
|
1088
|
+
cannot call =reject= (well, you can call it, but it won't have any impact on
|
|
1089
|
+
the fulfilment status of the promise). The problem arises when an event, for
|
|
1090
|
+
exmaple an =error= event is fired either after you have resolved a promise or
|
|
1091
|
+
possibly in-between promises. If you don't catch the =error= event, your
|
|
1092
|
+
script will likely crash with an =uncaught exception= error.
|
|
1093
|
+
|
|
1094
|
+
To make matters worse, some servers, particularly servers running on a
|
|
1095
|
+
Windows platform, will raise multiple errors for the same error /event/. For
|
|
1096
|
+
example, when you attempt to connect with a bad username or password, you
|
|
1097
|
+
will get a =All authentication methods have failed= exception. However, under
|
|
1098
|
+
Windows, you will also get a =Connection reset by peer= exception. If we
|
|
1099
|
+
reject the connect promise based on the authentication failure exception,
|
|
1100
|
+
what do we do with the =reset by peer= exception? More critically, what will
|
|
1101
|
+
handle that exception given the promise has already been fulfilled and
|
|
1102
|
+
completed? To make matters worse, it seems that Windows based servers also
|
|
1103
|
+
raise an error event for /non-errors/. For example, when you call the =end()=
|
|
1104
|
+
method, the connection is closed. On windows, this also results in a
|
|
1105
|
+
/connection reset by peer/ error. While it could be argued that the remote
|
|
1106
|
+
server resetting the connection after receiving a disconnect request is not
|
|
1107
|
+
an error, it doesn't change the fact that one is raised and we need to
|
|
1108
|
+
somehow deal with it.
|
|
1109
|
+
|
|
1110
|
+
To handle this, =ssh2-sftp-client= implements a couple of strategies.
|
|
1111
|
+
Firstly, when you call one of the module's methods, it adds =error=, =end=
|
|
1112
|
+
and =close= event listeners which will call the =reject= moethod on the
|
|
1113
|
+
enclosing promise. It also keeps track of whether an error has been handled
|
|
1114
|
+
and if it has, it ignores any subsequent errors until the promise ends.
|
|
1115
|
+
Typically, the first error caught has the most relevant information and any
|
|
1116
|
+
subsequent error events are less critical or informative, so ignoring them
|
|
1117
|
+
has no negative impact. Provided one of the events is raised before the
|
|
1118
|
+
promise is fulfilled, these handlers will consume the event and deal with it
|
|
1119
|
+
appropriately.
|
|
1120
|
+
|
|
1121
|
+
In testing, it was found that in some situations, particularly during connect
|
|
1122
|
+
operations, subsequent errors fired with a small delay. This prevents the
|
|
1123
|
+
errors from being handled by the event handlers associated with the connect
|
|
1124
|
+
promise. To deal with this, a small 500ms delay has been added to the
|
|
1125
|
+
connect() method, which effectively delays the removal of the event handlers
|
|
1126
|
+
until all events have been caught.
|
|
1127
|
+
|
|
1128
|
+
The other area where additional events are fired is during the end() call. To
|
|
1129
|
+
deal with these events, the =end()= method setus up listeners which will
|
|
1130
|
+
simply ignore additional =error=, =end= and =close= events. It is assumed
|
|
1131
|
+
that once you have called =end()= you really only care about any main error
|
|
1132
|
+
which occurs and no longer care about other errors that may be raised as the
|
|
1133
|
+
connection is terminated.
|
|
1134
|
+
|
|
1135
|
+
In addition to the promise based event handlers, =ssh2-sftp-client= also
|
|
1136
|
+
implements global event handlers which will catch any =error=, =end= or
|
|
1137
|
+
=close= events. Essentially, these global handlers only reset the =sftp=
|
|
1138
|
+
property of the client object, effectively ensuring any subsequent calls are
|
|
1139
|
+
rejected and in the case of an error, send the error to the console.
|
|
1140
|
+
|
|
1141
|
+
*** Adding Custom Handlers
|
|
1142
|
+
|
|
1143
|
+
While the above strategies appear to work for the majority of use cases,
|
|
1144
|
+
there are always going to be edge cases which require more flexible or
|
|
1145
|
+
powerful event handling. To support this, the =on()= and =removeListener()=
|
|
1146
|
+
methods are provided. Any event listener added using the =on()= method will
|
|
1147
|
+
be added at the beginning of the list of handlers for that event, ensuring
|
|
1148
|
+
it will be called before any global or promise local events. See the
|
|
1149
|
+
documentation for the =on()= method for details.
|
|
1150
|
+
|
|
1129
1151
|
** Windows Based Servers
|
|
1130
1152
|
|
|
1131
1153
|
It appears that when the sftp server is running on Windows, a /ECONNRESET/
|
|
@@ -1333,6 +1355,12 @@ host key used to establish the initial secure connection. See the SSH2
|
|
|
1333
1355
|
documentation for details. Getting these parameters correct usually resolves the
|
|
1334
1356
|
issue.
|
|
1335
1357
|
|
|
1358
|
+
When encountering this type of problem, one worthwhile approach is to use
|
|
1359
|
+
openSSH's CLI sftp program with the =-v= switch to raise loggin levels. This
|
|
1360
|
+
will show you what algorithms the CLI is using. You can then use this
|
|
1361
|
+
information to match the names with the accepted algorithm names documented in
|
|
1362
|
+
the =ssh2= README to set the properties in the =algorithms= object.
|
|
1363
|
+
|
|
1336
1364
|
** How can I limit upload/download speed
|
|
1337
1365
|
|
|
1338
1366
|
If you want to limit the amount of bandwidth used during upload/download of
|
|
@@ -1374,6 +1402,19 @@ issue.
|
|
|
1374
1402
|
await client.end();
|
|
1375
1403
|
}
|
|
1376
1404
|
#+end_src
|
|
1405
|
+
** Connection hangs or fails for larger files
|
|
1406
|
+
|
|
1407
|
+
This was contributed by Ladislav Jacho. Thanks.
|
|
1408
|
+
|
|
1409
|
+
A symptom of this issue is that you are able to upload small files, but
|
|
1410
|
+
uploading larger ones fail. You probably have an MTU/fragmentation problem. For
|
|
1411
|
+
each network interface on both client and server set the MTU to 576, e.g.
|
|
1412
|
+
=ifconfig eth0 mtu 576=. If that works, you need to find the largest MTU which
|
|
1413
|
+
will work for your network. An MTU which is too small will adversely affect
|
|
1414
|
+
throughput speed. A common value to use is an MTU of 1400.
|
|
1415
|
+
|
|
1416
|
+
For more explanation, see [[https://github.com/theophilusx/ssh2-sftp-client/issues/342][issue #342]].
|
|
1417
|
+
|
|
1377
1418
|
* Examples
|
|
1378
1419
|
|
|
1379
1420
|
I have started collecting example scripts in the example directory of the
|
|
@@ -1683,6 +1724,15 @@ tests and if your adding a new feature, that tests for that feature are
|
|
|
1683
1724
|
included. Likewise, for new features or enhancements, please include any
|
|
1684
1725
|
relevant documentation updates.
|
|
1685
1726
|
|
|
1727
|
+
*Note*: The =README.md= file is generated from the =README.org= file. Therefore,
|
|
1728
|
+
any documentation updates or fixes need to be made to the =README.org= file.
|
|
1729
|
+
This file is /tangled/ using =Emacs= org mode. If you don't use Emacs or
|
|
1730
|
+
org-mode, don't be too concerned. The org-mode syntax is straight-forward and
|
|
1731
|
+
similar to /markdown/. I will verify any updates to =README.org= and generate a
|
|
1732
|
+
new =README.md= when necessary. The main point to note is that any changes made
|
|
1733
|
+
directly to =README.md= will not persist and will be lost when a new version is
|
|
1734
|
+
generated, so don't modify that file.
|
|
1735
|
+
|
|
1686
1736
|
This module will adopt a standard semantic versioning policy. Please indicate in
|
|
1687
1737
|
your pull request what level of change it represents i.e.
|
|
1688
1738
|
|
|
@@ -1712,3 +1762,6 @@ Thanks to the following for their contributions -
|
|
|
1712
1762
|
- kennylbj :: Contributed example of using a throttle stream to limit
|
|
1713
1763
|
upload/download bandwidth.
|
|
1714
1764
|
- anton-erofeev :: Documentation fix
|
|
1765
|
+
- Ladislav Jacho :: Contributed solution explanation for connections hanging
|
|
1766
|
+
when transferring larger files.
|
|
1767
|
+
- Emma Milner :: Contributed fix for put() bug
|
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2-sftp-client",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4",
|
|
4
4
|
"description": "ssh2 sftp client for node",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/theophilusx/ssh2-sftp-client"
|
|
9
9
|
},
|
|
10
|
-
"keywords": [
|
|
10
|
+
"keywords": [
|
|
11
|
+
"sftp",
|
|
12
|
+
"nodejs",
|
|
13
|
+
"promises"
|
|
14
|
+
],
|
|
11
15
|
"scripts": {
|
|
12
16
|
"test": "mocha",
|
|
13
17
|
"coverage": "nyc npm run test",
|
|
14
|
-
"lint": "eslint \"src/**/*.js\"
|
|
18
|
+
"lint": "eslint \"src/**/*.js\" \"test/**/*.js\""
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=10.24.1"
|
|
15
22
|
},
|
|
16
23
|
"author": "Tim Cross",
|
|
17
24
|
"email": "theophilusx@gmail.com",
|
|
@@ -25,17 +32,24 @@
|
|
|
25
32
|
"dependencies": {
|
|
26
33
|
"concat-stream": "^2.0.0",
|
|
27
34
|
"promise-retry": "^2.0.1",
|
|
28
|
-
"ssh2": "^1.
|
|
35
|
+
"ssh2": "^1.4.0"
|
|
29
36
|
},
|
|
30
37
|
"devDependencies": {
|
|
31
38
|
"chai": "^4.2.0",
|
|
32
39
|
"chai-as-promised": "^7.1.1",
|
|
33
40
|
"chai-subset": "^1.6.0",
|
|
34
|
-
"checksum": "^0.
|
|
41
|
+
"checksum": "^1.0.0",
|
|
35
42
|
"dotenv": "^10.0.0",
|
|
36
|
-
"
|
|
43
|
+
"eslint": "^7.32.0",
|
|
44
|
+
"eslint-config-prettier": "^8.3.0",
|
|
45
|
+
"eslint-plugin-mocha": "^9.0.0",
|
|
46
|
+
"eslint-plugin-node": "^11.1.0",
|
|
47
|
+
"eslint-plugin-promise": "^5.1.0",
|
|
48
|
+
"eslint-plugin-unicorn": "^35.0.0",
|
|
49
|
+
"mocha": "^9.0.2",
|
|
37
50
|
"moment": "^2.29.1",
|
|
38
51
|
"nyc": "^15.1.0",
|
|
52
|
+
"prettier": "^2.3.2",
|
|
39
53
|
"through2": "^4.0.2",
|
|
40
54
|
"winston": "^3.3.3"
|
|
41
55
|
}
|
package/src/constants.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const errorCode = {
|
|
4
2
|
generic: 'ERR_GENERIC_CLIENT',
|
|
5
3
|
connect: 'ERR_NOT_CONNECTED',
|
|
6
4
|
badPath: 'ERR_BAD_PATH',
|
|
7
5
|
permission: 'EACCES',
|
|
8
6
|
notexist: 'ENOENT',
|
|
9
|
-
notdir: 'ENOTDIR'
|
|
7
|
+
notdir: 'ENOTDIR',
|
|
10
8
|
};
|
|
11
9
|
|
|
12
10
|
const targetType = {
|
|
@@ -15,10 +13,10 @@ const targetType = {
|
|
|
15
13
|
writeDir: 3,
|
|
16
14
|
readDir: 4,
|
|
17
15
|
readObj: 5,
|
|
18
|
-
writeObj: 6
|
|
16
|
+
writeObj: 6,
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
module.exports = {
|
|
22
20
|
errorCode,
|
|
23
|
-
targetType
|
|
21
|
+
targetType,
|
|
24
22
|
};
|