ssh2-sftp-client 9.0.0 → 9.0.3
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 +138 -131
- package/README.org +42 -21
- package/package.json +2 -2
- package/src/index.js +48 -126
- package/src/utils.js +38 -25
- package/.dir-local.el +0 -1
package/README.md
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
- [Overview](#
|
|
2
|
-
- [Version 9.x Changes](#
|
|
3
|
-
- [Installation](#
|
|
4
|
-
- [Basic Usage](#
|
|
5
|
-
- [Documentation](#
|
|
6
|
-
- [Specifying Paths](#
|
|
7
|
-
- [Methods](#
|
|
8
|
-
- [new SftpClient(name) ===> SFTP client object](#
|
|
9
|
-
- [connect(config) ===> SFTP object](#
|
|
10
|
-
- [list(path, filter) ==> Array[object]](#
|
|
11
|
-
- [exists(path) ==> boolean](#
|
|
12
|
-
- [stat(path) ==> object](#
|
|
13
|
-
- [get(path, dst, options) ==> String|Stream|Buffer](#
|
|
14
|
-
- [fastGet(remotePath, localPath, options) ===> string](#
|
|
15
|
-
- [put(src, remotePath, options) ==> string](#
|
|
16
|
-
- [fastPut(localPath, remotePath, options) ==> string](#
|
|
17
|
-
- [append(input, remotePath, options) ==> string](#
|
|
18
|
-
- [mkdir(path, recursive) ==> string](#
|
|
19
|
-
- [rmdir(path, recursive) ==> string](#
|
|
20
|
-
- [delete(path, noErrorOK) ==> string](#
|
|
21
|
-
- [rename(fromPath, toPath) ==> string](#
|
|
22
|
-
- [posixRename(fromPath, toPath) ==> string](#
|
|
23
|
-
- [chmod(path, mode) ==> string](#
|
|
24
|
-
- [realPath(path) ===> string](#
|
|
25
|
-
- [cwd() ==> string](#
|
|
26
|
-
- [uploadDir(srcDir, dstDir, options) ==> string](#
|
|
27
|
-
- [downloadDir(srcDir, dstDir, options) ==> string](#
|
|
28
|
-
- [createReadStream(remotePath, options)) ==> stream object](#
|
|
29
|
-
- [createWriteStream(remotePath, options) ==> stream object](#
|
|
30
|
-
- [rcopy(srcPath, dstPath) ==> string](#
|
|
31
|
-
- [end() ==> boolean](#
|
|
32
|
-
- [Add and Remove Listeners](#
|
|
33
|
-
- [Platform Quirks & Warnings](#
|
|
34
|
-
- [Server Capabilities](#
|
|
35
|
-
- [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- [
|
|
39
|
-
- [
|
|
40
|
-
|
|
41
|
-
- [
|
|
42
|
-
- [How can I
|
|
43
|
-
- [How can I
|
|
44
|
-
- [
|
|
45
|
-
- [
|
|
46
|
-
- [
|
|
47
|
-
- [
|
|
48
|
-
- [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- [
|
|
52
|
-
- [
|
|
53
|
-
- [
|
|
54
|
-
- [
|
|
55
|
-
|
|
56
|
-
- [
|
|
57
|
-
- [
|
|
58
|
-
- [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
- [Overview](#orgd38e3db)
|
|
2
|
+
- [Version 9.x Changes](#orgbc6dbf7)
|
|
3
|
+
- [Installation](#org8538ac8)
|
|
4
|
+
- [Basic Usage](#org0e586d6)
|
|
5
|
+
- [Documentation](#org8b956c0)
|
|
6
|
+
- [Specifying Paths](#orge4d511d)
|
|
7
|
+
- [Methods](#org54a5a5f)
|
|
8
|
+
- [new SftpClient(name) ===> SFTP client object](#org7e1be88)
|
|
9
|
+
- [connect(config) ===> SFTP object](#org4d439ac)
|
|
10
|
+
- [list(path, filter) ==> Array[object]](#org1cdf979)
|
|
11
|
+
- [exists(path) ==> boolean](#org27dfbbb)
|
|
12
|
+
- [stat(path) ==> object](#org989df3b)
|
|
13
|
+
- [get(path, dst, options) ==> String|Stream|Buffer](#orgc4730e8)
|
|
14
|
+
- [fastGet(remotePath, localPath, options) ===> string](#org2f58141)
|
|
15
|
+
- [put(src, remotePath, options) ==> string](#org6859ddc)
|
|
16
|
+
- [fastPut(localPath, remotePath, options) ==> string](#org62993ea)
|
|
17
|
+
- [append(input, remotePath, options) ==> string](#orgbac60b5)
|
|
18
|
+
- [mkdir(path, recursive) ==> string](#orgf266033)
|
|
19
|
+
- [rmdir(path, recursive) ==> string](#orgcb249fd)
|
|
20
|
+
- [delete(path, noErrorOK) ==> string](#orgfef0bf5)
|
|
21
|
+
- [rename(fromPath, toPath) ==> string](#org916cc1f)
|
|
22
|
+
- [posixRename(fromPath, toPath) ==> string](#org590854d)
|
|
23
|
+
- [chmod(path, mode) ==> string](#orgf437cd4)
|
|
24
|
+
- [realPath(path) ===> string](#org22161d6)
|
|
25
|
+
- [cwd() ==> string](#orgdba7a3a)
|
|
26
|
+
- [uploadDir(srcDir, dstDir, options) ==> string](#org583c51e)
|
|
27
|
+
- [downloadDir(srcDir, dstDir, options) ==> string](#orgc06694a)
|
|
28
|
+
- [createReadStream(remotePath, options)) ==> stream object](#org5163593)
|
|
29
|
+
- [createWriteStream(remotePath, options) ==> stream object](#orgbeba46f)
|
|
30
|
+
- [rcopy(srcPath, dstPath) ==> string](#orgfab48e5)
|
|
31
|
+
- [end() ==> boolean](#org9ffad87)
|
|
32
|
+
- [Add and Remove Listeners](#org5c294b3)
|
|
33
|
+
- [Platform Quirks & Warnings](#org6e33ff1)
|
|
34
|
+
- [Server Capabilities](#org0b56fde)
|
|
35
|
+
- [Issues with `fastPut()` and `fastGet()` Methods](#org7c6eba4)
|
|
36
|
+
- [Promises, Events & Managing Exceptions](#org38e15f9)
|
|
37
|
+
- [Adding Custom Handlers](#org10f1f65)
|
|
38
|
+
- [Windows Based Servers](#org7057905)
|
|
39
|
+
- [Don't Re-use SftpClient Objects](#org1775ff2)
|
|
40
|
+
- [FAQ](#org683ae73)
|
|
41
|
+
- [Remote server drops connections with only an end event](#org7e12a90)
|
|
42
|
+
- [How can I pass writable stream as dst for get method?](#org7f93e7e)
|
|
43
|
+
- [How can I upload files without having to specify a password?](#org6f24d1a)
|
|
44
|
+
- [How can I connect through a Socks Proxy](#org59a22c0)
|
|
45
|
+
- [Timeout while waiting for handshake or handshake errors](#org0439a3c)
|
|
46
|
+
- [How can I limit upload/download speed](#orge773153)
|
|
47
|
+
- [Connection hangs or fails for larger files](#orgf14374e)
|
|
48
|
+
- [Examples](#orge58bfb0)
|
|
49
|
+
- [Troubleshooting](#org5c3ee29)
|
|
50
|
+
- [Common Errors](#orgd46a3a1)
|
|
51
|
+
- [Not returning the promise in a `then()` block](#org41486a0)
|
|
52
|
+
- [Mixing Promise Chains and Async/Await](#org36f96d6)
|
|
53
|
+
- [Try/catch and Error Handlers](#org367d856)
|
|
54
|
+
- [Server Differences](#org180dea0)
|
|
55
|
+
- [Avoid Concurrent Operations](#org2bfd976)
|
|
56
|
+
- [Debugging Support](#org9590bf5)
|
|
57
|
+
- [Logging Issues](#orga4f395e)
|
|
58
|
+
- [Pull Requests](#orgbed06d9)
|
|
59
|
+
- [Contributors](#org7b575e4)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<a id="orgd38e3db"></a>
|
|
63
64
|
|
|
64
65
|
# Overview
|
|
65
66
|
|
|
@@ -67,17 +68,24 @@ an SFTP client for node.js, a wrapper around [SSH2](https://github.com/mscdex/ss
|
|
|
67
68
|
|
|
68
69
|
Documentation on the methods and available options in the underlying modules can be found on the [SSH2](https://github.com/mscdex/ssh2) project pages.
|
|
69
70
|
|
|
70
|
-
Current stable release is **v9.0.
|
|
71
|
+
Current stable release is **v9.0.2**.
|
|
71
72
|
|
|
72
73
|
Code has been tested against Node versions 14.19.1, 16.15.0 and 18.1.0
|
|
73
74
|
|
|
74
|
-
Node versions <
|
|
75
|
+
Node versions < 14.x are not supported.
|
|
75
76
|
|
|
76
77
|
|
|
77
|
-
<a id="
|
|
78
|
+
<a id="orgbc6dbf7"></a>
|
|
78
79
|
|
|
79
80
|
## Version 9.x Changes
|
|
80
81
|
|
|
82
|
+
- Fix bug in `end()` method where it was possible for the module to attempt calling the underlying ssh2 `end()` method when ssh2 has not been initialised. This could lead to undefined reference errors.
|
|
83
|
+
- Fix bug in `get()` method where supplied destination streams were not close, creating a possible resource leak. If the remote file did not exist, the method would return an error, but failed to close any passed in stream supplied as the destination for the data in the `get()` call.
|
|
84
|
+
- Change the default end and close handlers not to throw error or reject promises. Previously, an end or close event would cause an error to be raised or a promise to be rejected if the event was deemed to be *unexpected*. However, classification of events as being unexpected was unreliable and didn't add much real value. Both these handlers will now invalidate the sftp connection object and log that the event fired and nothing else.
|
|
85
|
+
- Changed when event handled flags are reset. Now they are reset after a new set of temporary listeners are added.
|
|
86
|
+
- Don't throw an error when calling end() if there is no active sftp connection. It does no harm to call end() when there is no connection, so no need to raise an error.
|
|
87
|
+
- Use nullish coalescing when setting retry parameters instead of or'ing with defaults. Allows setting values to 0.
|
|
88
|
+
- **Breaking Change**: This version uses syntax not supported in node versions prior to v14. Therefore, node versions less than v14 will not work.
|
|
81
89
|
- **Breaking Change**: This `list()` method no longer accepts a regular expression for filtering the entries to be returned. You can now specify a filter function instead. The function is called for each item in the list of items to be returned, passing in the item object as its only argument. Essentially, this is just a call to `Array.filter()`, so the filter function should behave in the same way i.e. return true for items to be retained and false for those to be dropped.
|
|
82
90
|
- **Breaking Change**: The ability to set `autoClose` on read and write streams and the ability to set `end` on `pipe` operations has been removed. These options caused confusion for users and were too easy to get wrong, plus it made the methods overly complicated. For those use-cases where you want to control streams at a low level, two new methods have been added, `createReadStream()` and `createWriteStream()`. However, it should be noted that client code is 100% responsible for managing streams obtained using these methods. Use at your own risk!
|
|
83
91
|
- **Breaking Change**: The 3rd argument to `uploadDir()` and `downloadDir()` methods has been change. Previously, the argument was a filter function used to select which directories and files to be transferred. The 3rd argument is now an options object with two supported properties, `filter` and `useFastput` (for `uploadDir()`) or `useFastget` (for `downloadDir()`). If `useFastput` is true, the `fastPut()` method will be pused to upload files. If `false` or missing, the slower, but better supported, `put()` method will be used. Likewise, the `useFastget` options can be set to `true` to use the `fastGet()` method for donwloading files, otherwise the slower, but more reliable, `get()` method will be used.
|
|
@@ -88,7 +96,7 @@ Node versions < 12.x are not supported. However, node v10.x should still work, a
|
|
|
88
96
|
- Bumped ssh2 version to 1.11.0
|
|
89
97
|
|
|
90
98
|
|
|
91
|
-
<a id="
|
|
99
|
+
<a id="org8538ac8"></a>
|
|
92
100
|
|
|
93
101
|
# Installation
|
|
94
102
|
|
|
@@ -97,7 +105,7 @@ npm install ssh2-sftp-client
|
|
|
97
105
|
```
|
|
98
106
|
|
|
99
107
|
|
|
100
|
-
<a id="
|
|
108
|
+
<a id="org0e586d6"></a>
|
|
101
109
|
|
|
102
110
|
# Basic Usage
|
|
103
111
|
|
|
@@ -120,7 +128,7 @@ sftp.connect({
|
|
|
120
128
|
```
|
|
121
129
|
|
|
122
130
|
|
|
123
|
-
<a id="
|
|
131
|
+
<a id="org8b956c0"></a>
|
|
124
132
|
|
|
125
133
|
# Documentation
|
|
126
134
|
|
|
@@ -129,7 +137,7 @@ The connection options are the same as those offered by the underlying SSH2 modu
|
|
|
129
137
|
All the methods will return a Promise, except for `on()` and `removeListener()`, which are typically only used in special use cases.
|
|
130
138
|
|
|
131
139
|
|
|
132
|
-
<a id="
|
|
140
|
+
<a id="orge4d511d"></a>
|
|
133
141
|
|
|
134
142
|
## Specifying Paths
|
|
135
143
|
|
|
@@ -162,12 +170,12 @@ client.put('/home/fred/test.txt', '/remote/dir/test-copy.txt');
|
|
|
162
170
|
This will copy the local file `test.txt` to the remote file `test-copy.txt` in the directory `/remote/dir`.
|
|
163
171
|
|
|
164
172
|
|
|
165
|
-
<a id="
|
|
173
|
+
<a id="org54a5a5f"></a>
|
|
166
174
|
|
|
167
175
|
## Methods
|
|
168
176
|
|
|
169
177
|
|
|
170
|
-
<a id="
|
|
178
|
+
<a id="org7e1be88"></a>
|
|
171
179
|
|
|
172
180
|
### new SftpClient(name) ===> SFTP client object
|
|
173
181
|
|
|
@@ -206,7 +214,7 @@ Constructor to create a new `ssh2-sftp-client` object. An optional `name` string
|
|
|
206
214
|
```
|
|
207
215
|
|
|
208
216
|
|
|
209
|
-
<a id="
|
|
217
|
+
<a id="org4d439ac"></a>
|
|
210
218
|
|
|
211
219
|
### connect(config) ===> SFTP object
|
|
212
220
|
|
|
@@ -272,7 +280,7 @@ Connect to an sftp server. Full documentation for connection options is availabl
|
|
|
272
280
|
```
|
|
273
281
|
|
|
274
282
|
|
|
275
|
-
<a id="
|
|
283
|
+
<a id="org1cdf979"></a>
|
|
276
284
|
|
|
277
285
|
### list(path, filter) ==> Array[object]
|
|
278
286
|
|
|
@@ -332,18 +340,8 @@ Retrieves a directory listing. This method returns a Promise, which once realise
|
|
|
332
340
|
}
|
|
333
341
|
```
|
|
334
342
|
|
|
335
|
-
3. Pattern Filter
|
|
336
|
-
|
|
337
|
-
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.
|
|
338
|
-
|
|
339
|
-
foo* => foo, foobar, foobaz
|
|
340
|
-
*bar => bar, foobar, tabbar
|
|
341
|
-
*oo* => foo, foobar, look, book
|
|
342
|
-
|
|
343
|
-
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.
|
|
344
343
|
|
|
345
|
-
|
|
346
|
-
<a id="orgaae7860"></a>
|
|
344
|
+
<a id="org27dfbbb"></a>
|
|
347
345
|
|
|
348
346
|
### exists(path) ==> boolean
|
|
349
347
|
|
|
@@ -379,7 +377,7 @@ Tests to see if remote file or directory exists. Returns type of remote object i
|
|
|
379
377
|
```
|
|
380
378
|
|
|
381
379
|
|
|
382
|
-
<a id="
|
|
380
|
+
<a id="org989df3b"></a>
|
|
383
381
|
|
|
384
382
|
### stat(path) ==> object
|
|
385
383
|
|
|
@@ -430,7 +428,7 @@ Returns the attributes associated with the object pointed to by `path`.
|
|
|
430
428
|
```
|
|
431
429
|
|
|
432
430
|
|
|
433
|
-
<a id="
|
|
431
|
+
<a id="orgc4730e8"></a>
|
|
434
432
|
|
|
435
433
|
### get(path, dst, options) ==> String|Stream|Buffer
|
|
436
434
|
|
|
@@ -486,7 +484,7 @@ In general, if you're going to pass in a string as the destination, you are bett
|
|
|
486
484
|
- **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'.
|
|
487
485
|
|
|
488
486
|
|
|
489
|
-
<a id="
|
|
487
|
+
<a id="org2f58141"></a>
|
|
490
488
|
|
|
491
489
|
### fastGet(remotePath, localPath, options) ===> string
|
|
492
490
|
|
|
@@ -529,7 +527,7 @@ Downloads a file at remotePath to localPath using parallel reads for faster thro
|
|
|
529
527
|
```
|
|
530
528
|
|
|
531
529
|
|
|
532
|
-
<a id="
|
|
530
|
+
<a id="org6859ddc"></a>
|
|
533
531
|
|
|
534
532
|
### put(src, remotePath, options) ==> string
|
|
535
533
|
|
|
@@ -579,7 +577,7 @@ Upload data from local system to remote server. If the `src` argument is a strin
|
|
|
579
577
|
- **Tip:** If the src argument is a path string, consider just using `fastPut()`.
|
|
580
578
|
|
|
581
579
|
|
|
582
|
-
<a id="
|
|
580
|
+
<a id="org62993ea"></a>
|
|
583
581
|
|
|
584
582
|
### fastPut(localPath, remotePath, options) ==> string
|
|
585
583
|
|
|
@@ -623,7 +621,7 @@ Uploads the data in file at `localPath` to a new file on remote server at `remot
|
|
|
623
621
|
```
|
|
624
622
|
|
|
625
623
|
|
|
626
|
-
<a id="
|
|
624
|
+
<a id="orgbac60b5"></a>
|
|
627
625
|
|
|
628
626
|
### append(input, remotePath, options) ==> string
|
|
629
627
|
|
|
@@ -667,7 +665,7 @@ Append the `input` data to an existing remote file. There is no integrity checki
|
|
|
667
665
|
```
|
|
668
666
|
|
|
669
667
|
|
|
670
|
-
<a id="
|
|
668
|
+
<a id="orgf266033"></a>
|
|
671
669
|
|
|
672
670
|
### mkdir(path, recursive) ==> string
|
|
673
671
|
|
|
@@ -695,7 +693,7 @@ Create a new directory. If the recursive flag is set to true, the method will cr
|
|
|
695
693
|
```
|
|
696
694
|
|
|
697
695
|
|
|
698
|
-
<a id="
|
|
696
|
+
<a id="orgcb249fd"></a>
|
|
699
697
|
|
|
700
698
|
### rmdir(path, recursive) ==> string
|
|
701
699
|
|
|
@@ -725,7 +723,7 @@ Remove a directory. If removing a directory and recursive flag is set to `true`,
|
|
|
725
723
|
```
|
|
726
724
|
|
|
727
725
|
|
|
728
|
-
<a id="
|
|
726
|
+
<a id="orgfef0bf5"></a>
|
|
729
727
|
|
|
730
728
|
### delete(path, noErrorOK) ==> string
|
|
731
729
|
|
|
@@ -754,7 +752,7 @@ Delete a file on the remote server.
|
|
|
754
752
|
```
|
|
755
753
|
|
|
756
754
|
|
|
757
|
-
<a id="
|
|
755
|
+
<a id="org916cc1f"></a>
|
|
758
756
|
|
|
759
757
|
### rename(fromPath, toPath) ==> string
|
|
760
758
|
|
|
@@ -783,7 +781,7 @@ Rename a file or directory from `fromPath` to `toPath`. You must have the necess
|
|
|
783
781
|
```
|
|
784
782
|
|
|
785
783
|
|
|
786
|
-
<a id="
|
|
784
|
+
<a id="org590854d"></a>
|
|
787
785
|
|
|
788
786
|
### posixRename(fromPath, toPath) ==> string
|
|
789
787
|
|
|
@@ -810,7 +808,7 @@ client.connect(config)
|
|
|
810
808
|
```
|
|
811
809
|
|
|
812
810
|
|
|
813
|
-
<a id="
|
|
811
|
+
<a id="orgf437cd4"></a>
|
|
814
812
|
|
|
815
813
|
### chmod(path, mode) ==> string
|
|
816
814
|
|
|
@@ -839,7 +837,7 @@ Change the mode (read, write or execute permissions) of a remote file or directo
|
|
|
839
837
|
```
|
|
840
838
|
|
|
841
839
|
|
|
842
|
-
<a id="
|
|
840
|
+
<a id="org22161d6"></a>
|
|
843
841
|
|
|
844
842
|
### realPath(path) ===> string
|
|
845
843
|
|
|
@@ -850,14 +848,14 @@ Converts a relative path to an absolute path on the remote server. This method i
|
|
|
850
848
|
- **path:** A file path, either relative or absolute. Can handle '.' and '..', but does not expand '~'.
|
|
851
849
|
|
|
852
850
|
|
|
853
|
-
<a id="
|
|
851
|
+
<a id="orgdba7a3a"></a>
|
|
854
852
|
|
|
855
853
|
### cwd() ==> string
|
|
856
854
|
|
|
857
855
|
Returns what the server believes is the current remote working directory.
|
|
858
856
|
|
|
859
857
|
|
|
860
|
-
<a id="
|
|
858
|
+
<a id="org583c51e"></a>
|
|
861
859
|
|
|
862
860
|
### uploadDir(srcDir, dstDir, options) ==> string
|
|
863
861
|
|
|
@@ -926,7 +924,7 @@ The `useFastput` option is a boolean option. If `true`, the method will use the
|
|
|
926
924
|
```
|
|
927
925
|
|
|
928
926
|
|
|
929
|
-
<a id="
|
|
927
|
+
<a id="orgc06694a"></a>
|
|
930
928
|
|
|
931
929
|
### downloadDir(srcDir, dstDir, options) ==> string
|
|
932
930
|
|
|
@@ -991,7 +989,7 @@ If the `useFastget` property is set to `true`, the method will use `fastGet()` t
|
|
|
991
989
|
```
|
|
992
990
|
|
|
993
991
|
|
|
994
|
-
<a id="
|
|
992
|
+
<a id="org5163593"></a>
|
|
995
993
|
|
|
996
994
|
### createReadStream(remotePath, options)) ==> stream object
|
|
997
995
|
|
|
@@ -1008,7 +1006,7 @@ Returns a read stream object which is attached to the remote file specified by t
|
|
|
1008
1006
|
- **end:** Postion to stop reading bytes (inclusive).
|
|
1009
1007
|
|
|
1010
1008
|
|
|
1011
|
-
<a id="
|
|
1009
|
+
<a id="orgbeba46f"></a>
|
|
1012
1010
|
|
|
1013
1011
|
### createWriteStream(remotePath, options) ==> stream object
|
|
1014
1012
|
|
|
@@ -1023,7 +1021,7 @@ Returns a write stream object which is attached to the remote file specified in
|
|
|
1023
1021
|
- **start:** Byte position to start writing from (inclusive). May require changing flag to 'r+'.
|
|
1024
1022
|
|
|
1025
1023
|
|
|
1026
|
-
<a id="
|
|
1024
|
+
<a id="orgfab48e5"></a>
|
|
1027
1025
|
|
|
1028
1026
|
### rcopy(srcPath, dstPath) ==> string
|
|
1029
1027
|
|
|
@@ -1033,7 +1031,7 @@ Perfrom a remote file copy. The file identified by the `srcPath` argument will b
|
|
|
1033
1031
|
- **dstPath:** Path to where the copy will be creaeted specified as a string
|
|
1034
1032
|
|
|
1035
1033
|
|
|
1036
|
-
<a id="
|
|
1034
|
+
<a id="org9ffad87"></a>
|
|
1037
1035
|
|
|
1038
1036
|
### end() ==> boolean
|
|
1039
1037
|
|
|
@@ -1057,7 +1055,7 @@ Ends the current client session, releasing the client socket and associated reso
|
|
|
1057
1055
|
```
|
|
1058
1056
|
|
|
1059
1057
|
|
|
1060
|
-
<a id="
|
|
1058
|
+
<a id="org5c294b3"></a>
|
|
1061
1059
|
|
|
1062
1060
|
### Add and Remove Listeners
|
|
1063
1061
|
|
|
@@ -1078,12 +1076,12 @@ Although normally not required, you can add and remove custom listeners on the s
|
|
|
1078
1076
|
Removes the specified listener from the event specified in eventType. Note that the `end()` method automatically removes all listeners from the client object.
|
|
1079
1077
|
|
|
1080
1078
|
|
|
1081
|
-
<a id="
|
|
1079
|
+
<a id="org6e33ff1"></a>
|
|
1082
1080
|
|
|
1083
1081
|
# Platform Quirks & Warnings
|
|
1084
1082
|
|
|
1085
1083
|
|
|
1086
|
-
<a id="
|
|
1084
|
+
<a id="org0b56fde"></a>
|
|
1087
1085
|
|
|
1088
1086
|
## Server Capabilities
|
|
1089
1087
|
|
|
@@ -1092,7 +1090,16 @@ All SFTP servers and platforms are not equal. Some facilities provided by `ssh2-
|
|
|
1092
1090
|
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.
|
|
1093
1091
|
|
|
1094
1092
|
|
|
1095
|
-
<a id="
|
|
1093
|
+
<a id="org7c6eba4"></a>
|
|
1094
|
+
|
|
1095
|
+
## Issues with `fastPut()` and `fastGet()` Methods
|
|
1096
|
+
|
|
1097
|
+
The `fastPut()` and `fastGet()` methods are known to be somewhat dependent on SFTP server capabilities. Some SFTP servers just do not work correctly with concurrent connections and some are known to have issues with negotiating packet sizes. These issues can sometimes be resolved by tweaking the options supplied to the methods, such as setting number of concurrent connections or a psecific packet size.
|
|
1098
|
+
|
|
1099
|
+
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.
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
<a id="org38e15f9"></a>
|
|
1096
1103
|
|
|
1097
1104
|
## Promises, Events & Managing Exceptions
|
|
1098
1105
|
|
|
@@ -1111,14 +1118,14 @@ The other area where additional events are fired is during the end() call. To de
|
|
|
1111
1118
|
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.
|
|
1112
1119
|
|
|
1113
1120
|
|
|
1114
|
-
<a id="
|
|
1121
|
+
<a id="org10f1f65"></a>
|
|
1115
1122
|
|
|
1116
1123
|
### Adding Custom Handlers
|
|
1117
1124
|
|
|
1118
1125
|
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.
|
|
1119
1126
|
|
|
1120
1127
|
|
|
1121
|
-
<a id="
|
|
1128
|
+
<a id="org7057905"></a>
|
|
1122
1129
|
|
|
1123
1130
|
## Windows Based Servers
|
|
1124
1131
|
|
|
@@ -1127,7 +1134,7 @@ It appears that when the sftp server is running on Windows, a *ECONNRESET* error
|
|
|
1127
1134
|
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.
|
|
1128
1135
|
|
|
1129
1136
|
|
|
1130
|
-
<a id="
|
|
1137
|
+
<a id="org1775ff2"></a>
|
|
1131
1138
|
|
|
1132
1139
|
## Don't Re-use SftpClient Objects
|
|
1133
1140
|
|
|
@@ -1136,12 +1143,12 @@ Due to an issue with *ECONNRESET* error signals when connecting to Windows based
|
|
|
1136
1143
|
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.
|
|
1137
1144
|
|
|
1138
1145
|
|
|
1139
|
-
<a id="
|
|
1146
|
+
<a id="org683ae73"></a>
|
|
1140
1147
|
|
|
1141
1148
|
# FAQ
|
|
1142
1149
|
|
|
1143
1150
|
|
|
1144
|
-
<a id="
|
|
1151
|
+
<a id="org7e12a90"></a>
|
|
1145
1152
|
|
|
1146
1153
|
## Remote server drops connections with only an end event
|
|
1147
1154
|
|
|
@@ -1152,7 +1159,7 @@ Clients first make an unauthenticated connection to the SFTP server to begin neg
|
|
|
1152
1159
|
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.
|
|
1153
1160
|
|
|
1154
1161
|
|
|
1155
|
-
<a id="
|
|
1162
|
+
<a id="org7f93e7e"></a>
|
|
1156
1163
|
|
|
1157
1164
|
## How can I pass writable stream as dst for get method?
|
|
1158
1165
|
|
|
@@ -1211,7 +1218,7 @@ sftp
|
|
|
1211
1218
|
```
|
|
1212
1219
|
|
|
1213
1220
|
|
|
1214
|
-
<a id="
|
|
1221
|
+
<a id="org6f24d1a"></a>
|
|
1215
1222
|
|
|
1216
1223
|
## How can I upload files without having to specify a password?
|
|
1217
1224
|
|
|
@@ -1246,7 +1253,7 @@ sftp.connect({
|
|
|
1246
1253
|
```
|
|
1247
1254
|
|
|
1248
1255
|
|
|
1249
|
-
<a id="
|
|
1256
|
+
<a id="org59a22c0"></a>
|
|
1250
1257
|
|
|
1251
1258
|
## How can I connect through a Socks Proxy
|
|
1252
1259
|
|
|
@@ -1282,7 +1289,7 @@ client.connect({
|
|
|
1282
1289
|
```
|
|
1283
1290
|
|
|
1284
1291
|
|
|
1285
|
-
<a id="
|
|
1292
|
+
<a id="org0439a3c"></a>
|
|
1286
1293
|
|
|
1287
1294
|
## Timeout while waiting for handshake or handshake errors
|
|
1288
1295
|
|
|
@@ -1291,7 +1298,7 @@ Some users have encountered the error 'Timeout while waiting for handshake' or '
|
|
|
1291
1298
|
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.
|
|
1292
1299
|
|
|
1293
1300
|
|
|
1294
|
-
<a id="
|
|
1301
|
+
<a id="orge773153"></a>
|
|
1295
1302
|
|
|
1296
1303
|
## How can I limit upload/download speed
|
|
1297
1304
|
|
|
@@ -1331,7 +1338,7 @@ try {
|
|
|
1331
1338
|
```
|
|
1332
1339
|
|
|
1333
1340
|
|
|
1334
|
-
<a id="
|
|
1341
|
+
<a id="orgf14374e"></a>
|
|
1335
1342
|
|
|
1336
1343
|
## Connection hangs or fails for larger files
|
|
1337
1344
|
|
|
@@ -1342,14 +1349,14 @@ A symptom of this issue is that you are able to upload small files, but uploadin
|
|
|
1342
1349
|
For more explanation, see [issue #342](https://github.com/theophilusx/ssh2-sftp-client/issues/342).
|
|
1343
1350
|
|
|
1344
1351
|
|
|
1345
|
-
<a id="
|
|
1352
|
+
<a id="orge58bfb0"></a>
|
|
1346
1353
|
|
|
1347
1354
|
# Examples
|
|
1348
1355
|
|
|
1349
1356
|
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.
|
|
1350
1357
|
|
|
1351
1358
|
|
|
1352
|
-
<a id="
|
|
1359
|
+
<a id="org5c3ee29"></a>
|
|
1353
1360
|
|
|
1354
1361
|
# Troubleshooting
|
|
1355
1362
|
|
|
@@ -1364,14 +1371,14 @@ Note also that in the repository there are two useful directories. The first is
|
|
|
1364
1371
|
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.
|
|
1365
1372
|
|
|
1366
1373
|
|
|
1367
|
-
<a id="
|
|
1374
|
+
<a id="orgd46a3a1"></a>
|
|
1368
1375
|
|
|
1369
1376
|
## Common Errors
|
|
1370
1377
|
|
|
1371
1378
|
There are some common errors people tend to make when using Promises or Asyc/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.
|
|
1372
1379
|
|
|
1373
1380
|
|
|
1374
|
-
<a id="
|
|
1381
|
+
<a id="org41486a0"></a>
|
|
1375
1382
|
|
|
1376
1383
|
### Not returning the promise in a `then()` block
|
|
1377
1384
|
|
|
@@ -1408,7 +1415,7 @@ Note the `return` statements. These ensure that the Promise returned by the clie
|
|
|
1408
1415
|
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.
|
|
1409
1416
|
|
|
1410
1417
|
|
|
1411
|
-
<a id="
|
|
1418
|
+
<a id="org36f96d6"></a>
|
|
1412
1419
|
|
|
1413
1420
|
### Mixing Promise Chains and Async/Await
|
|
1414
1421
|
|
|
@@ -1468,7 +1475,7 @@ async function doSftp() {
|
|
|
1468
1475
|
```
|
|
1469
1476
|
|
|
1470
1477
|
|
|
1471
|
-
<a id="
|
|
1478
|
+
<a id="org367d856"></a>
|
|
1472
1479
|
|
|
1473
1480
|
### Try/catch and Error Handlers
|
|
1474
1481
|
|
|
@@ -1479,14 +1486,14 @@ The basic problem is that the try/catch block will have completed execution befo
|
|
|
1479
1486
|
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.
|
|
1480
1487
|
|
|
1481
1488
|
|
|
1482
|
-
<a id="
|
|
1489
|
+
<a id="org180dea0"></a>
|
|
1483
1490
|
|
|
1484
1491
|
### Server Differences
|
|
1485
1492
|
|
|
1486
1493
|
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.
|
|
1487
1494
|
|
|
1488
1495
|
|
|
1489
|
-
<a id="
|
|
1496
|
+
<a id="org2bfd976"></a>
|
|
1490
1497
|
|
|
1491
1498
|
### Avoid Concurrent Operations
|
|
1492
1499
|
|
|
@@ -1495,7 +1502,7 @@ Technically, SFTP should be able to perform multiple operations concurrently. As
|
|
|
1495
1502
|
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.
|
|
1496
1503
|
|
|
1497
1504
|
|
|
1498
|
-
<a id="
|
|
1505
|
+
<a id="org9590bf5"></a>
|
|
1499
1506
|
|
|
1500
1507
|
## Debugging Support
|
|
1501
1508
|
|
|
@@ -1528,7 +1535,7 @@ If you just want to see debug messages from `ssh2-sftp-client` and exclude debug
|
|
|
1528
1535
|
```
|
|
1529
1536
|
|
|
1530
1537
|
|
|
1531
|
-
<a id="
|
|
1538
|
+
<a id="orga4f395e"></a>
|
|
1532
1539
|
|
|
1533
1540
|
# Logging Issues
|
|
1534
1541
|
|
|
@@ -1545,7 +1552,7 @@ I am happy to try and help diagnose and fix any issues you encounter while using
|
|
|
1545
1552
|
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.
|
|
1546
1553
|
|
|
1547
1554
|
|
|
1548
|
-
<a id="
|
|
1555
|
+
<a id="orgbed06d9"></a>
|
|
1549
1556
|
|
|
1550
1557
|
# Pull Requests
|
|
1551
1558
|
|
|
@@ -1560,7 +1567,7 @@ This module will adopt a standard semantic versioning policy. Please indicate in
|
|
|
1560
1567
|
- **Bug Fix:** No change to functionality or features. Simple fix of an existing bug.
|
|
1561
1568
|
|
|
1562
1569
|
|
|
1563
|
-
<a id="
|
|
1570
|
+
<a id="org7b575e4"></a>
|
|
1564
1571
|
|
|
1565
1572
|
# Contributors
|
|
1566
1573
|
|