ssh2-sftp-client 12.1.0 → 12.1.1

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 CHANGED
@@ -1,70 +1,71 @@
1
- - [Overview](#orge272967)
2
- - [Version 12.0.0 Changes](#org9688783)
3
- - [Version 12.0.1 Changes](#org6c6cbc7)
4
- - [Version 12.1.0 Changes](#org678bfad)
5
- - [Background](#org41ff3b3)
6
- - [Installation](#org64016b3)
7
- - [Basic Usage](#org0cbc36d)
8
- - [Documentation](#org161d25d)
9
- - [Specifying Paths](#org569c530)
10
- - [Methods](#orge938fe1)
11
- - [new SftpClient(name, callbacks) ===> SFTP client object](#org87fb7cb)
12
- - [connect(config) ===> SFTP object](#org00cd0ef)
13
- - [list(path, filter) ==> Array[object]](#org2471bc8)
14
- - [exists(path) ==> boolean](#org69f0979)
15
- - [stat(path) ==> object](#org70605b0)
16
- - [get(path, dst, options) ==> String|Stream|Buffer](#org6ef818c)
17
- - [fastGet(remotePath, localPath, options) ===> string](#org4be5f02)
18
- - [put(src, remotePath, options) ==> string](#org29892b8)
19
- - [fastPut(localPath, remotePath, options) ==> string](#org8b51862)
20
- - [append(input, remotePath, options) ==> string](#org60825d3)
21
- - [mkdir(path, recursive) ==> string](#orga9278dd)
22
- - [rmdir(path, recursive) ==> string](#org49dc87c)
23
- - [delete(path, noErrorOK) ==> string](#orgbe8caee)
24
- - [rename(fromPath, toPath) ==> string](#orgc525c46)
25
- - [posixRename(fromPath, toPath) ==> string](#org72d1dcb)
26
- - [chmod(path, mode) ==> string](#org0c71566)
27
- - [realPath(path) ===> string](#org7dcfedc)
28
- - [cwd() ==> string](#orgdaa63b2)
29
- - [uploadDir(srcDir, dstDir, options) ==> string](#orgf47dba2)
30
- - [downloadDir(srcDir, dstDir, options) ==> string](#orgc046861)
31
- - [createReadStream(remotePath, options)) ==> stream object](#orgbb40821)
32
- - [createWriteStream(remotePath, options) ==> stream object](#org5b94858)
33
- - [rcopy(srcPath, dstPath) ==> string](#org352c030)
34
- - [end() ==> boolean](#org9591ce4)
35
- - [Add and Remove Listeners](#org5f4115d)
36
- - [Platform Quirks & Warnings](#org99f279a)
37
- - [Server Capabilities](#org5f13ec7)
38
- - [Issues with `fastPut()` and `fastGet()` Methods](#org0580b2e)
39
- - [Promises, Events & Managing Exceptions](#org836ad16)
40
- - [Adding Custom Handlers](#org7eb04eb)
41
- - [Windows Based Servers](#org64d4763)
42
- - [Don't Re-use SftpClient Objects](#org4e39c0f)
43
- - [FAQ](#org55e6f0b)
44
- - [Remote server drops connections with only an end event](#orgbba8948)
45
- - [How can I pass writeable stream as dst for get method?](#org3380bb0)
46
- - [How can I upload files without having to specify a password?](#org144745f)
47
- - [How can I connect through a Socks Proxy](#org65cf78c)
48
- - [Timeout while waiting for handshake or handshake errors](#orgc1209ba)
49
- - [How can I limit upload/download speed](#orgec6bc5b)
50
- - [Connection hangs or fails for larger files](#org222771b)
51
- - [Typescript definition file out of date](#org64453a9)
52
- - [Examples](#orge079610)
53
- - [Troubleshooting](#orgedc17fd)
54
- - [Common Errors](#org7756613)
55
- - [Not returning the promise in a `then()` block](#orgdf44163)
56
- - [Mixing Promise Chains and Async/Await](#org643899f)
57
- - [Try/catch and Error Handlers](#orgf1586cd)
58
- - [Server Differences](#org57723b9)
59
- - [Avoid Concurrent Operations](#org8f56d89)
60
- - [Debugging Support](#org4c34184)
61
- - [Logging Issues](#org63b74c6)
62
- - [Pull Requests](#org308be7d)
63
- - [Contributors](#org585b558)
64
-
65
-
66
-
67
- <a id="orge272967"></a>
1
+ - [Overview](#org6987c45)
2
+ - [Version 12.0.0 Changes](#org02987aa)
3
+ - [Version 12.0.1 Changes](#org7468421)
4
+ - [Version 12.1.0 Changes](#orge1b539d)
5
+ - [Version 12.1.1 Changes](#orged5d608)
6
+ - [Background](#orge45f641)
7
+ - [Installation](#org660793d)
8
+ - [Basic Usage](#org25ec48d)
9
+ - [Documentation](#org70c6bcd)
10
+ - [Specifying Paths](#org6e11821)
11
+ - [Methods](#orgac96e89)
12
+ - [new SftpClient(name, callbacks) ===> SFTP client object](#org5a43218)
13
+ - [connect(config) ===> SFTP object](#org2204c82)
14
+ - [list(path, filter) ==> Array[object]](#org6412c07)
15
+ - [exists(path) ==> boolean](#org538f718)
16
+ - [stat(path) ==> object](#org49ddb80)
17
+ - [get(path, dst, options) ==> String|Stream|Buffer](#org7a94a2b)
18
+ - [fastGet(remotePath, localPath, options) ===> string](#orgc9d1d0f)
19
+ - [put(src, remotePath, options) ==> string](#orgd1b5df0)
20
+ - [fastPut(localPath, remotePath, options) ==> string](#orga70daaf)
21
+ - [append(input, remotePath, options) ==> string](#org44bf28c)
22
+ - [mkdir(path, recursive) ==> string](#org79f8f19)
23
+ - [rmdir(path, recursive) ==> string](#org01678bc)
24
+ - [delete(path, noErrorOK) ==> string](#org7aa4867)
25
+ - [rename(fromPath, toPath) ==> string](#orgfeb9fe0)
26
+ - [posixRename(fromPath, toPath) ==> string](#orgcde5734)
27
+ - [chmod(path, mode) ==> string](#org9a2be14)
28
+ - [realPath(path) ===> string](#orgfa8caf6)
29
+ - [cwd() ==> string](#org712492d)
30
+ - [uploadDir(srcDir, dstDir, options) ==> string](#org4c58675)
31
+ - [downloadDir(srcDir, dstDir, options) ==> string](#orgd4cec94)
32
+ - [createReadStream(remotePath, options)) ==> stream object](#orgaf8232d)
33
+ - [createWriteStream(remotePath, options) ==> stream object](#orgb90e976)
34
+ - [rcopy(srcPath, dstPath) ==> string](#org8da7dd9)
35
+ - [end() ==> boolean](#orgefc8914)
36
+ - [Add and Remove Listeners](#org9bc7c20)
37
+ - [Platform Quirks & Warnings](#org141ea6c)
38
+ - [Server Capabilities](#org02bda70)
39
+ - [Issues with `fastPut()` and `fastGet()` Methods](#org7039cad)
40
+ - [Promises, Events & Managing Exceptions](#org6f0f2d3)
41
+ - [Adding Custom Handlers](#orga3bd20f)
42
+ - [Windows Based Servers](#orgd17159d)
43
+ - [Don't Re-use SftpClient Objects](#orgbabcbec)
44
+ - [FAQ](#orge56389f)
45
+ - [Remote server drops connections with only an end event](#orga1e4f59)
46
+ - [How can I pass writeable stream as dst for get method?](#org6bd3606)
47
+ - [How can I upload files without having to specify a password?](#orgec27c87)
48
+ - [How can I connect through a Socks Proxy](#org1f7a40b)
49
+ - [Timeout while waiting for handshake or handshake errors](#orge77b90c)
50
+ - [How can I limit upload/download speed](#org0a65ef0)
51
+ - [Connection hangs or fails for larger files](#org042cb9c)
52
+ - [Typescript definition file out of date](#orgd1fa8b1)
53
+ - [Examples](#org4a3c46b)
54
+ - [Troubleshooting](#org1c383d5)
55
+ - [Common Errors](#org3a2df1c)
56
+ - [Not returning the promise in a `then()` block](#orgd9b95f7)
57
+ - [Mixing Promise Chains and Async/Await](#orgd62dd8c)
58
+ - [Try/catch and Error Handlers](#orgf1cdec9)
59
+ - [Server Differences](#orgf717a07)
60
+ - [Avoid Concurrent Operations](#orge7917a5)
61
+ - [Debugging Support](#org5aa5efa)
62
+ - [Logging Issues](#org0475065)
63
+ - [Pull Requests](#org954dbfa)
64
+ - [Contributors](#orgaa3b2aa)
65
+
66
+
67
+
68
+ <a id="org6987c45"></a>
68
69
 
69
70
  # Overview
70
71
 
@@ -72,14 +73,14 @@ This package provides the class SftpClient, an SFTP client for node.js. It is a
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) project pages. As the ssh2-sftp-client package is just a wrapper around the `ssh2` module, you will find lots of useful information, tips and examples in the `ssh2` repository.
74
75
 
75
- Current stable release is \*v12.1.0.
76
+ Current stable release is \*v12.1.1.
76
77
 
77
78
  Code has been tested against Node versions 24.14.0. Node versions prior to v20.x are not supported.
78
79
 
79
80
  If you find this module useful and you would like to support the on-going maintenance and support of users, please consider making a small [donation](https://square.link/u/gB2kSdkY?src=embed).
80
81
 
81
82
 
82
- <a id="org9688783"></a>
83
+ <a id="org02987aa"></a>
83
84
 
84
85
  ## Version 12.0.0 Changes
85
86
 
@@ -88,7 +89,7 @@ The big and breaking change in this version is the removal of the connection ret
88
89
  Another reason this functionality was removed is because if you really want it, it is straight forward to create your own wrapper around the connect call which uses one of the mnay promise retry packages available. It is much simpler to add a retry mechanism for a specific application than it is to implement a flexible solution which supports all possible combination of connection options, authentication methods, proxies etc.
89
90
 
90
91
 
91
- <a id="org6c6cbc7"></a>
92
+ <a id="org7468421"></a>
92
93
 
93
94
  ## Version 12.0.1 Changes
94
95
 
@@ -99,14 +100,23 @@ Bug Fixes
99
100
  - Added calls to \_resetEventFlags() to finally clauses to ensure event flags are reset when temp listeners are removed. Without this change, global listeners would not fire when they should after their has been an earlier handled error in the last API call.
100
101
 
101
102
 
102
- <a id="org678bfad"></a>
103
+ <a id="orge1b539d"></a>
103
104
 
104
105
  ## Version 12.1.0 Changes
105
106
 
106
107
  The main change in this version is to address an issue with disconnect when accessing Microsoft's SFTP server. Due to the way the Microsoft server implements closing of connections, an exception is thrown even when there has been a legitimate request to end the connection. The fix is to ignore this specific *error* case. Thanks to @rhyswilliamsza for the patch.
107
108
 
108
109
 
109
- <a id="org41ff3b3"></a>
110
+ <a id="orged5d608"></a>
111
+
112
+ ## Version 12.1.1 Changes
113
+
114
+ Just a minor bug fix for the error handlers. Ensure that the sftp object is invalidated after any ECONNRESET to ensure any further attempts to use the sftp connection fail immediately. Previously, there was an edge case where a connect abruptly closed by the remote server could result in either a long timeout error or a hanging promise which never fulfills or rejects. Now the internal sftp object is cleared whenever a ECONNRESET event occurs as this event indicates the remote server has closed the connection.
115
+
116
+ Note that as ECONNRESET events are triggered by the remote server closing the connection, there is little error information the client can report. It is generally necessary to check the remote SFTP server logs in order to determine why the remote server closed the connection.
117
+
118
+
119
+ <a id="orge45f641"></a>
110
120
 
111
121
  ## Background
112
122
 
@@ -145,7 +155,7 @@ In some cases, no end event is raised and you only get an error event followed b
145
155
  In order to handle the possible hanging issue in version 11, the temporary promise linked end and close listeners have been updated to always call the promise's reject function if they fire. While this works, it can cause a minor issue. As wse cannot gurantee the order in which events are responded to by listeners, it is possible that either the end or close listener may be executed before the error listener. When this occurs, the promise is rejected, but the only information wse have at that point is that the promise wsas reject due to either an end or close event. We don't yet have any details regarding what error has caused the unexpected end or close event. Furthermore, because only the first promise resolution function call has any effect, calling reject within the error listener (assuming an error event does eventually arrive) has no effect and does not communicate error information back to the caller. This means that in some circumstances, especially when working with some poorly behaved sftp servers, an sftp connection will be lost/closed with no indication as to reason. This can make diagnosis and bug tracking frustrating.
146
156
 
147
157
 
148
- <a id="org64016b3"></a>
158
+ <a id="org660793d"></a>
149
159
 
150
160
  # Installation
151
161
 
@@ -154,7 +164,7 @@ npm install ssh2-sftp-client
154
164
  ```
155
165
 
156
166
 
157
- <a id="org0cbc36d"></a>
167
+ <a id="org25ec48d"></a>
158
168
 
159
169
  # Basic Usage
160
170
 
@@ -177,7 +187,7 @@ sftp.connect({
177
187
  ```
178
188
 
179
189
 
180
- <a id="org161d25d"></a>
190
+ <a id="org70c6bcd"></a>
181
191
 
182
192
  # Documentation
183
193
 
@@ -188,7 +198,7 @@ All the methods will return a Promise, except for `on(), ~removeListener()`, `cr
188
198
  Note that I don't use Typescript and I don't maintain any typescript definition files. There are some typescript type definition files for this module, but they are maintained separately and have nothing to do with this project. Therefore, please do not log any issues arising from the use of these definition files with this project. Instead, refer your issues to the maintainers of those modules.
189
199
 
190
200
 
191
- <a id="org569c530"></a>
201
+ <a id="org6e11821"></a>
192
202
 
193
203
  ## Specifying Paths
194
204
 
@@ -221,12 +231,12 @@ client.put('/home/fred/test.txt', '/remote/dir/test-copy.txt');
221
231
  This will copy the local file `test.txt` to the remote file `test-copy.txt` in the directory `/remote/dir`.
222
232
 
223
233
 
224
- <a id="orge938fe1"></a>
234
+ <a id="orgac96e89"></a>
225
235
 
226
236
  ## Methods
227
237
 
228
238
 
229
- <a id="org87fb7cb"></a>
239
+ <a id="org5a43218"></a>
230
240
 
231
241
  ### new SftpClient(name, callbacks) ===> SFTP client object
232
242
 
@@ -266,7 +276,7 @@ Constructor to create a new `ssh2-sftp-client` object. An optional `name` string
266
276
  ```
267
277
 
268
278
 
269
- <a id="org00cd0ef"></a>
279
+ <a id="org2204c82"></a>
270
280
 
271
281
  ### connect(config) ===> SFTP object
272
282
 
@@ -330,7 +340,7 @@ Connect to an sftp server. Full documentation for connection options is availabl
330
340
  ```
331
341
 
332
342
 
333
- <a id="org2471bc8"></a>
343
+ <a id="org6412c07"></a>
334
344
 
335
345
  ### list(path, filter) ==> Array[object]
336
346
 
@@ -391,7 +401,7 @@ Retrieves a directory listing. This method returns a Promise, which once realise
391
401
  ```
392
402
 
393
403
 
394
- <a id="org69f0979"></a>
404
+ <a id="org538f718"></a>
395
405
 
396
406
  ### exists(path) ==> boolean
397
407
 
@@ -427,7 +437,7 @@ Tests to see if remote file or directory exists. Returns type of remote object i
427
437
  ```
428
438
 
429
439
 
430
- <a id="org70605b0"></a>
440
+ <a id="org49ddb80"></a>
431
441
 
432
442
  ### stat(path) ==> object
433
443
 
@@ -478,7 +488,7 @@ Returns the attributes associated with the object pointed to by `path`.
478
488
  ```
479
489
 
480
490
 
481
- <a id="org6ef818c"></a>
491
+ <a id="org7a94a2b"></a>
482
492
 
483
493
  ### get(path, dst, options) ==> String|Stream|Buffer
484
494
 
@@ -534,7 +544,7 @@ In general, if you're going to pass in a string as the destination, you are bett
534
544
  - **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'.
535
545
 
536
546
 
537
- <a id="org4be5f02"></a>
547
+ <a id="orgc9d1d0f"></a>
538
548
 
539
549
  ### fastGet(remotePath, localPath, options) ===> string
540
550
 
@@ -579,7 +589,7 @@ Bottom line, when it works, it tends to work reliably. However, for many servers
579
589
  ```
580
590
 
581
591
 
582
- <a id="org29892b8"></a>
592
+ <a id="orgd1b5df0"></a>
583
593
 
584
594
  ### put(src, remotePath, options) ==> string
585
595
 
@@ -629,7 +639,7 @@ Upload data from local system to remote server. If the `src` argument is a strin
629
639
  - **Tip:** If the src argument is a path string, consider just using `fastPut()`.
630
640
 
631
641
 
632
- <a id="org8b51862"></a>
642
+ <a id="orga70daaf"></a>
633
643
 
634
644
  ### fastPut(localPath, remotePath, options) ==> string
635
645
 
@@ -675,7 +685,7 @@ Bottom line, when it works, it tends to work well. However, when it doesn't work
675
685
  ```
676
686
 
677
687
 
678
- <a id="org60825d3"></a>
688
+ <a id="org44bf28c"></a>
679
689
 
680
690
  ### append(input, remotePath, options) ==> string
681
691
 
@@ -719,7 +729,7 @@ Append the `input` data to an existing remote file. There is no integrity checki
719
729
  ```
720
730
 
721
731
 
722
- <a id="orga9278dd"></a>
732
+ <a id="org79f8f19"></a>
723
733
 
724
734
  ### mkdir(path, recursive) ==> string
725
735
 
@@ -747,7 +757,7 @@ Create a new directory. If the recursive flag is set to true, the method will cr
747
757
  ```
748
758
 
749
759
 
750
- <a id="org49dc87c"></a>
760
+ <a id="org01678bc"></a>
751
761
 
752
762
  ### rmdir(path, recursive) ==> string
753
763
 
@@ -777,7 +787,7 @@ Remove a directory. If removing a directory and recursive flag is set to `true`,
777
787
  ```
778
788
 
779
789
 
780
- <a id="orgbe8caee"></a>
790
+ <a id="org7aa4867"></a>
781
791
 
782
792
  ### delete(path, noErrorOK) ==> string
783
793
 
@@ -806,7 +816,7 @@ Delete a file on the remote server.
806
816
  ```
807
817
 
808
818
 
809
- <a id="orgc525c46"></a>
819
+ <a id="orgfeb9fe0"></a>
810
820
 
811
821
  ### rename(fromPath, toPath) ==> string
812
822
 
@@ -835,7 +845,7 @@ Rename a file or directory from `fromPath` to `toPath`. You must have the necess
835
845
  ```
836
846
 
837
847
 
838
- <a id="org72d1dcb"></a>
848
+ <a id="orgcde5734"></a>
839
849
 
840
850
  ### posixRename(fromPath, toPath) ==> string
841
851
 
@@ -862,7 +872,7 @@ client.connect(config)
862
872
  ```
863
873
 
864
874
 
865
- <a id="org0c71566"></a>
875
+ <a id="org9a2be14"></a>
866
876
 
867
877
  ### chmod(path, mode) ==> string
868
878
 
@@ -891,7 +901,7 @@ Change the mode (read, write or execute permissions) of a remote file or directo
891
901
  ```
892
902
 
893
903
 
894
- <a id="org7dcfedc"></a>
904
+ <a id="orgfa8caf6"></a>
895
905
 
896
906
  ### realPath(path) ===> string
897
907
 
@@ -902,14 +912,14 @@ Converts a relative path to an absolute path on the remote server. This method i
902
912
  - **path:** A file path, either relative or absolute. Can handle '.' and '..', but does not expand '~'.
903
913
 
904
914
 
905
- <a id="orgdaa63b2"></a>
915
+ <a id="org712492d"></a>
906
916
 
907
917
  ### cwd() ==> string
908
918
 
909
919
  Returns what the server believes is the current remote working directory.
910
920
 
911
921
 
912
- <a id="orgf47dba2"></a>
922
+ <a id="org4c58675"></a>
913
923
 
914
924
  ### uploadDir(srcDir, dstDir, options) ==> string
915
925
 
@@ -978,7 +988,7 @@ The `useFastput` option is a boolean option. If `true`, the method will use the
978
988
  ```
979
989
 
980
990
 
981
- <a id="orgc046861"></a>
991
+ <a id="orgd4cec94"></a>
982
992
 
983
993
  ### downloadDir(srcDir, dstDir, options) ==> string
984
994
 
@@ -1043,7 +1053,7 @@ If the `useFastget` property is set to `true`, the method will use `fastGet()` t
1043
1053
  ```
1044
1054
 
1045
1055
 
1046
- <a id="orgbb40821"></a>
1056
+ <a id="orgaf8232d"></a>
1047
1057
 
1048
1058
  ### createReadStream(remotePath, options)) ==> stream object
1049
1059
 
@@ -1060,7 +1070,7 @@ Returns a read stream object which is attached to the remote file specified by t
1060
1070
  - **end:** Position to stop reading bytes (inclusive).
1061
1071
 
1062
1072
 
1063
- <a id="org5b94858"></a>
1073
+ <a id="orgb90e976"></a>
1064
1074
 
1065
1075
  ### createWriteStream(remotePath, options) ==> stream object
1066
1076
 
@@ -1075,7 +1085,7 @@ Returns a write stream object which is attached to the remote file specified in
1075
1085
  - **start:** Byte position to start writing from (inclusive). May require changing flag to 'r+'.
1076
1086
 
1077
1087
 
1078
- <a id="org352c030"></a>
1088
+ <a id="org8da7dd9"></a>
1079
1089
 
1080
1090
  ### rcopy(srcPath, dstPath) ==> string
1081
1091
 
@@ -1085,7 +1095,7 @@ Perform a remote file copy. The file identified by the `srcPath` argument will b
1085
1095
  - **dstPath:** Path to where the copy will be created specified as a string
1086
1096
 
1087
1097
 
1088
- <a id="org9591ce4"></a>
1098
+ <a id="orgefc8914"></a>
1089
1099
 
1090
1100
  ### end() ==> boolean
1091
1101
 
@@ -1109,7 +1119,7 @@ Ends the current client session, releasing the client socket and associated reso
1109
1119
  ```
1110
1120
 
1111
1121
 
1112
- <a id="org5f4115d"></a>
1122
+ <a id="org9bc7c20"></a>
1113
1123
 
1114
1124
  ### Add and Remove Listeners
1115
1125
 
@@ -1130,12 +1140,12 @@ Although normally not required, you can add and remove custom listeners on the s
1130
1140
  Removes the specified listener from the event specified in eventType. Note that the `end()` method automatically removes all listeners from the client object.
1131
1141
 
1132
1142
 
1133
- <a id="org99f279a"></a>
1143
+ <a id="org141ea6c"></a>
1134
1144
 
1135
1145
  # Platform Quirks & Warnings
1136
1146
 
1137
1147
 
1138
- <a id="org5f13ec7"></a>
1148
+ <a id="org02bda70"></a>
1139
1149
 
1140
1150
  ## Server Capabilities
1141
1151
 
@@ -1144,7 +1154,7 @@ All SFTP servers and platforms are not equal. Some facilities provided by `ssh2-
1144
1154
  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.
1145
1155
 
1146
1156
 
1147
- <a id="org0580b2e"></a>
1157
+ <a id="org7039cad"></a>
1148
1158
 
1149
1159
  ## Issues with `fastPut()` and `fastGet()` Methods
1150
1160
 
@@ -1153,7 +1163,7 @@ The `fastPut()` and `fastGet()` methods are known to be somewhat dependent on SF
1153
1163
  To see an example of the type of issues you can observe with `fastPut()` or `fastGet()`, have a look at [issue 407](https://github.com/theophilusx/ssh2-sftp-client/issues/407), which describes the experiences of one user. Bottom line, when it works, it tends to work well and be significantly faster than using just `get()` or `put()`. However, when developing code to run against different SFTP servers, especially where you are unable to test against each server, you are likely better off just using `get()` and `put()` or structuring your code so that users can select which method to use (this is what `ssh2-sftp-client` does - for example, see the `!downloadDir()` and `uploadDir()` methods.
1154
1164
 
1155
1165
 
1156
- <a id="org836ad16"></a>
1166
+ <a id="org6f0f2d3"></a>
1157
1167
 
1158
1168
  ## Promises, Events & Managing Exceptions
1159
1169
 
@@ -1172,14 +1182,14 @@ The other area where additional events are fired is during the end() call. To de
1172
1182
  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.
1173
1183
 
1174
1184
 
1175
- <a id="org7eb04eb"></a>
1185
+ <a id="orga3bd20f"></a>
1176
1186
 
1177
1187
  ### Adding Custom Handlers
1178
1188
 
1179
1189
  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.
1180
1190
 
1181
1191
 
1182
- <a id="org64d4763"></a>
1192
+ <a id="orgd17159d"></a>
1183
1193
 
1184
1194
  ## Windows Based Servers
1185
1195
 
@@ -1188,7 +1198,7 @@ It appears that when the sftp server is running on Windows, a *ECONNRESET* error
1188
1198
  The best way to avoid this issue is to not re-use client objects. Always generate a new sftp client object for each new connection.
1189
1199
 
1190
1200
 
1191
- <a id="org4e39c0f"></a>
1201
+ <a id="orgbabcbec"></a>
1192
1202
 
1193
1203
  ## Don't Re-use SftpClient Objects
1194
1204
 
@@ -1197,12 +1207,12 @@ Due to an issue with *ECONNRESET* error signals when connecting to Windows based
1197
1207
  To avoid this problem, don't re-use SftpClient objects. Generate a new SftpClient object for each connection. You can perform multiple actions with a single connection e.g. upload multiple files, download multiple files etc, but after you have called end(), you should not try to re-use the object with a further connect() call. Create a new object instead.
1198
1208
 
1199
1209
 
1200
- <a id="org55e6f0b"></a>
1210
+ <a id="orge56389f"></a>
1201
1211
 
1202
1212
  # FAQ
1203
1213
 
1204
1214
 
1205
- <a id="orgbba8948"></a>
1215
+ <a id="orga1e4f59"></a>
1206
1216
 
1207
1217
  ## Remote server drops connections with only an end event
1208
1218
 
@@ -1213,7 +1223,7 @@ Clients first make an unauthenticated connection to the SFTP server to begin neg
1213
1223
  One way to avoid this type of issue is to add a delay between connection attempts. It does not need to be a very long delay - just sufficient to permit the previous connection to be authenticated. In fact, the default setting for openSSH is `10:30:60`, so you really just need to have enough delay to ensure that the 1st connection has completed authentication before the 11th connection is attempted.
1214
1224
 
1215
1225
 
1216
- <a id="org3380bb0"></a>
1226
+ <a id="org6bd3606"></a>
1217
1227
 
1218
1228
  ## How can I pass writeable stream as dst for get method?
1219
1229
 
@@ -1272,7 +1282,7 @@ sftp
1272
1282
  ```
1273
1283
 
1274
1284
 
1275
- <a id="org144745f"></a>
1285
+ <a id="orgec27c87"></a>
1276
1286
 
1277
1287
  ## How can I upload files without having to specify a password?
1278
1288
 
@@ -1307,7 +1317,7 @@ sftp.connect({
1307
1317
  ```
1308
1318
 
1309
1319
 
1310
- <a id="org65cf78c"></a>
1320
+ <a id="org1f7a40b"></a>
1311
1321
 
1312
1322
  ## How can I connect through a Socks Proxy
1313
1323
 
@@ -1344,7 +1354,7 @@ client.connect({
1344
1354
  ```
1345
1355
 
1346
1356
 
1347
- <a id="orgc1209ba"></a>
1357
+ <a id="orge77b90c"></a>
1348
1358
 
1349
1359
  ## Timeout while waiting for handshake or handshake errors
1350
1360
 
@@ -1353,7 +1363,7 @@ Some users have encountered the error 'Timeout while waiting for handshake' or '
1353
1363
  When encountering this type of problem, one worthwhile approach is to use openSSH's CLI sftp program with the `-v` switch to raise logging 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.
1354
1364
 
1355
1365
 
1356
- <a id="orgec6bc5b"></a>
1366
+ <a id="org0a65ef0"></a>
1357
1367
 
1358
1368
  ## How can I limit upload/download speed
1359
1369
 
@@ -1393,7 +1403,7 @@ try {
1393
1403
  ```
1394
1404
 
1395
1405
 
1396
- <a id="org222771b"></a>
1406
+ <a id="org042cb9c"></a>
1397
1407
 
1398
1408
  ## Connection hangs or fails for larger files
1399
1409
 
@@ -1404,21 +1414,21 @@ A symptom of this issue is that you are able to upload small files, but uploadin
1404
1414
  For more explanation, see [issue #342](https://github.com/theophilusx/ssh2-sftp-client/issues/342).
1405
1415
 
1406
1416
 
1407
- <a id="org64453a9"></a>
1417
+ <a id="orgd1fa8b1"></a>
1408
1418
 
1409
1419
  ## Typescript definition file out of date
1410
1420
 
1411
1421
  This project does not use Typescript. However, typescript definition files are provided by other 3rd parties. Sometimes, these definition files have not stayed up-to-date with the current version of this module. If you encounter this issue, you need to report it to the party responsible for the definition file, not this project.
1412
1422
 
1413
1423
 
1414
- <a id="orge079610"></a>
1424
+ <a id="org4a3c46b"></a>
1415
1425
 
1416
1426
  # Examples
1417
1427
 
1418
1428
  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.
1419
1429
 
1420
1430
 
1421
- <a id="orgedc17fd"></a>
1431
+ <a id="org1c383d5"></a>
1422
1432
 
1423
1433
  # Troubleshooting
1424
1434
 
@@ -1433,14 +1443,14 @@ Note also that in the repository there are two useful directories. The first is
1433
1443
  The second directory is the validation directory. I have some very simple scripts in this directory which perform basic tasks using only the `ssh2` modules (no `ssh2-sftp-client` module). These can be useful when trying to determine if the issue is with the underlying `ssh2` module or the `ssh2-sftp-client` wrapper module.
1434
1444
 
1435
1445
 
1436
- <a id="org7756613"></a>
1446
+ <a id="org3a2df1c"></a>
1437
1447
 
1438
1448
  ## Common Errors
1439
1449
 
1440
1450
  There are some common errors people tend to make when using Promises or Async/Await. These are by far the most common problem found in issues logged against this module. Please check for some of these before logging your issue.
1441
1451
 
1442
1452
 
1443
- <a id="orgdf44163"></a>
1453
+ <a id="orgd9b95f7"></a>
1444
1454
 
1445
1455
  ### Not returning the promise in a `then()` block
1446
1456
 
@@ -1477,7 +1487,7 @@ Note the `return` statements. These ensure that the Promise returned by the clie
1477
1487
  A common symptom of this type of error is for file uploads or download to fail to complete or for data in those files to be truncated. What is happening is that the connection is being ended before the transfer has completed.
1478
1488
 
1479
1489
 
1480
- <a id="org643899f"></a>
1490
+ <a id="orgd62dd8c"></a>
1481
1491
 
1482
1492
  ### Mixing Promise Chains and Async/Await
1483
1493
 
@@ -1537,7 +1547,7 @@ async function doSftp() {
1537
1547
  ```
1538
1548
 
1539
1549
 
1540
- <a id="orgf1586cd"></a>
1550
+ <a id="orgf1cdec9"></a>
1541
1551
 
1542
1552
  ### Try/catch and Error Handlers
1543
1553
 
@@ -1548,14 +1558,14 @@ The basic problem is that the try/catch block will have completed execution befo
1548
1558
  Error events are essentially asynchronous code. You don't know when such events will fire. Therefore, you cannot use a try/catch block to catch such event errors. Even creating an error handler which then throws an exception won't help as the key problem is that your try/catch block has already executed. There are a number of alternative ways to deal with this situation. However, the key symptom is that you see occasional uncaught error exceptions that cause your script to exit abnormally despite having try/catch blocks in your script. What you need to do is look at your code and find where errors are raised asynchronously and use an event handler or some other mechanism to manage any errors raised.
1549
1559
 
1550
1560
 
1551
- <a id="org57723b9"></a>
1561
+ <a id="orgf717a07"></a>
1552
1562
 
1553
1563
  ### Server Differences
1554
1564
 
1555
1565
  Not all SFTP servers are the same. Like most standards, the SFTP protocol has some level of interpretation and allows different levels of compliance. This means there can be differences in behaviour between different servers and code which works with one server will not work the same with another. For example, the value returned by *realpath* for non-existent objects can differ significantly. Some servers will throw an error for a particular operation while others will just return null, some servers support concurrent operations (such as used by fastGet/fastPut) while others will not and of course, the text of error messages can vary significantly. In particular, we have noticed significant differences across different platforms. It is therefore advisable to do comprehensive testing when the SFTP server is moved to a new platform. This includes moving from to a cloud based service even if the underlying platform remains the same. I have noticed that some cloud platforms can generate unexpected events, possibly related to additional functionality or features associated with the cloud implementation. For example, it appears SFTP servers running under Azure will generate an error event when the connection is closed even when the client has requested the connection be terminated. The same SFTP server running natively on Windows does not appear to exhibit such behaviour.
1556
1566
 
1557
1567
 
1558
- <a id="org8f56d89"></a>
1568
+ <a id="orge7917a5"></a>
1559
1569
 
1560
1570
  ### Avoid Concurrent Operations
1561
1571
 
@@ -1564,7 +1574,7 @@ Technically, SFTP should be able to perform multiple operations concurrently. As
1564
1574
  If you are going to try and perform concurrent operations, you need to test extensively and ensure you are using data which is large enough that context switching does occur (i.e. the request is not completed in a single run). Some SFTP servers will handle concurrent operations better than others.
1565
1575
 
1566
1576
 
1567
- <a id="org4c34184"></a>
1577
+ <a id="org5aa5efa"></a>
1568
1578
 
1569
1579
  ## Debugging Support
1570
1580
 
@@ -1597,7 +1607,7 @@ If you just want to see debug messages from `ssh2-sftp-client` and exclude debug
1597
1607
  ```
1598
1608
 
1599
1609
 
1600
- <a id="org63b74c6"></a>
1610
+ <a id="org0475065"></a>
1601
1611
 
1602
1612
  # Logging Issues
1603
1613
 
@@ -1614,7 +1624,7 @@ I am happy to try and help diagnose and fix any issues you encounter while using
1614
1624
  Perhaps the best assistance is a minimal reproducible example of the issue. Once the issue can be readily reproduced, it can usually be fixed very quickly.
1615
1625
 
1616
1626
 
1617
- <a id="org308be7d"></a>
1627
+ <a id="org954dbfa"></a>
1618
1628
 
1619
1629
  # Pull Requests
1620
1630
 
@@ -1631,7 +1641,7 @@ This module will adopt a standard semantic versioning policy. Please indicate in
1631
1641
  - **Bug Fix:** No change to functionality or features. Simple fix of an existing bug.
1632
1642
 
1633
1643
 
1634
- <a id="org585b558"></a>
1644
+ <a id="orgaa3b2aa"></a>
1635
1645
 
1636
1646
  # Contributors
1637
1647
 
package/README.org CHANGED
@@ -12,7 +12,7 @@ be found on the [[https://github.com/mscdex/ssh2][SSH2]] project pages. As the s
12
12
  ~ssh2~ module, you will find lots of useful information, tips and examples in the ~ssh2~
13
13
  repository.
14
14
 
15
- Current stable release is *v12.1.0.
15
+ Current stable release is *v12.1.1.
16
16
 
17
17
  Code has been tested against Node versions 24.14.0. Node versions prior to v20.x are not
18
18
  supported.
@@ -60,6 +60,20 @@ possible combination of connection options, authentication methods, proxies etc.
60
60
  the connection. The fix is to ignore this specific /error/ case. Thanks to @rhyswilliamsza
61
61
  for the patch.
62
62
 
63
+ ** Version 12.1.1 Changes
64
+
65
+ Just a minor bug fix for the error handlers. Ensure that the sftp object is invalidated
66
+ after any ECONNRESET to ensure any further attempts to use the sftp connection fail
67
+ immediately. Previously, there was an edge case where a connect abruptly closed by the
68
+ remote server could result in either a long timeout error or a hanging promise which never
69
+ fulfills or rejects. Now the internal sftp object is cleared whenever a ECONNRESET event
70
+ occurs as this event indicates the remote server has closed the connection.
71
+
72
+ Note that as ECONNRESET events are triggered by the remote server closing the connection,
73
+ there is little error information the client can report. It is generally necessary to
74
+ check the remote SFTP server logs in order to determine why the remote server closed the
75
+ connection.
76
+
63
77
  ** Background
64
78
 
65
79
  In basic terms =ssh2-sftp-client= is a simple wrapper around the =ssh2= package which provides
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh2-sftp-client",
3
- "version": "12.1.0",
3
+ "version": "12.1.1",
4
4
  "description": "ssh2 sftp client for node",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/utils.js CHANGED
@@ -69,6 +69,9 @@ function errorListener(client, name, reject) {
69
69
  client.debugMsg(`${name} errorListener - ignoring ${err.message} on end`);
70
70
  return;
71
71
  }
72
+ if (err.code === 'ECONNRESET') {
73
+ client.sftp = undefined;
74
+ }
72
75
  client.debugMsg(`${name} errorListener - handling error ${err.message}`);
73
76
  client.errorHandled = true;
74
77
  const newError = new Error(`${name}: ${err.message}`);