diff --git a/README.md b/README.md
index b572b9d..0e109ec 100644
--- a/README.md
+++ b/README.md
@@ -1,68 +1,65 @@
-- [Overview](#org320c38d)
- - [Version 9.x Changes](#org6815b1f)
-- [Installation](#orgf0d7e7e)
-- [Basic Usage](#org076abca)
-- [Documentation](#orge6c1dc9)
- - [Specifying Paths](#orgb20b6a3)
- - [Methods](#orgb394515)
- - [new SftpClient(name) ===> SFTP client object](#org58340c0)
- - [connect(config) ===> SFTP object](#org62f210f)
- - [list(path, filter) ==> Array[object]](#orgaac2c09)
- - [exists(path) ==> boolean](#org24131e6)
- - [stat(path) ==> object](#orgb367df6)
- - [get(path, dst, options) ==> String|Stream|Buffer](#org07de343)
- - [fastGet(remotePath, localPath, options) ===> string](#orgf6461f0)
- - [put(src, remotePath, options) ==> string](#org80dbf6d)
- - [fastPut(localPath, remotePath, options) ==> string](#org2fe55d4)
- - [append(input, remotePath, options) ==> string](#org99abc81)
- - [mkdir(path, recursive) ==> string](#org1fb1161)
- - [rmdir(path, recursive) ==> string](#org4321952)
- - [delete(path, noErrorOK) ==> string](#orga8c0ed6)
- - [rename(fromPath, toPath) ==> string](#orgec7ebd5)
- - [posixRename(fromPath, toPath) ==> string](#org5026062)
- - [chmod(path, mode) ==> string](#org415ab46)
- - [realPath(path) ===> string](#orga346293)
- - [cwd() ==> string](#org241c8c9)
- - [uploadDir(srcDir, dstDir, options) ==> string](#org251a03a)
- - [downloadDir(srcDir, dstDir, options) ==> string](#org88deaf4)
- - [createReadStream(remotePath, options)) ==> stream object](#org4b5fc0d)
- - [createWriteStream(remotePath, options) ==> stream object](#org3a2ebb6)
- - [rcopy(srcPath, dstPath) ==> string](#org00b929f)
- - [end() ==> boolean](#org767ebc6)
- - [Add and Remove Listeners](#orga93fef3)
-- [Platform Quirks & Warnings](#orgf6dbd36)
- - [Server Capabilities](#org62e8c37)
- - [Issues with `fastPut()` and `fastGet()` Methods](#org7c3b092)
- - [Promises, Events & Managing Exceptions](#orgd8f3dee)
- - [Adding Custom Handlers](#org3e34ed7)
- - [Windows Based Servers](#org148fb8e)
- - [Don't Re-use SftpClient Objects](#orge138d90)
-- [FAQ](#org0f36cc9)
- - [Remote server drops connections with only an end event](#org1ae0567)
- - [How can I pass writable stream as dst for get method?](#org029a40a)
- - [How can I upload files without having to specify a password?](#orged561eb)
- - [How can I connect through a Socks Proxy](#org6ca5d93)
- - [Timeout while waiting for handshake or handshake errors](#org50ac6bf)
- - [How can I limit upload/download speed](#org9496c39)
- - [Connection hangs or fails for larger files](#org75f23a3)
-- [Examples](#org63c3da3)
-- [Troubleshooting](#org975c5e0)
- - [Common Errors](#org46252f1)
- - [Not returning the promise in a `then()` block](#orgf0ea5fc)
- - [Mixing Promise Chains and Async/Await](#orgf756366)
- - [Try/catch and Error Handlers](#orgfffceef)
- - [Server Differences](#org7f525d0)
- - [Avoid Concurrent Operations](#org1131072)
- - [Debugging Support](#orgc7155f9)
-- [Logging Issues](#orgc01b4fa)
-- [Pull Requests](#org7a9c677)
-- [Contributors](#orgaa3553c)
-
-
-
-
-
-# Overview
+- [Overview](#sec-1)
+ - [Version 9.x Changes](#sec-1-1)
+- [Installation](#sec-2)
+- [Basic Usage](#sec-3)
+- [Documentation](#sec-4)
+ - [Specifying Paths](#sec-4-1)
+ - [Methods](#sec-4-2)
+ - [new SftpClient(name) ===> SFTP client object](#sec-4-2-1)
+ - [connect(config) ===> SFTP object](#sec-4-2-2)
+ - [list(path, filter) ==> Array[object]](#sec-4-2-3)
+ - [exists(path) ==> boolean](#sec-4-2-4)
+ - [stat(path) ==> object](#sec-4-2-5)
+ - [get(path, dst, options) ==> String|Stream|Buffer](#sec-4-2-6)
+ - [fastGet(remotePath, localPath, options) ===> string](#sec-4-2-7)
+ - [put(src, remotePath, options) ==> string](#sec-4-2-8)
+ - [fastPut(localPath, remotePath, options) ==> string](#sec-4-2-9)
+ - [append(input, remotePath, options) ==> string](#sec-4-2-10)
+ - [mkdir(path, recursive) ==> string](#sec-4-2-11)
+ - [rmdir(path, recursive) ==> string](#sec-4-2-12)
+ - [delete(path, noErrorOK) ==> string](#sec-4-2-13)
+ - [rename(fromPath, toPath) ==> string](#sec-4-2-14)
+ - [posixRename(fromPath, toPath) ==> string](#sec-4-2-15)
+ - [chmod(path, mode) ==> string](#sec-4-2-16)
+ - [realPath(path) ===> string](#sec-4-2-17)
+ - [cwd() ==> string](#sec-4-2-18)
+ - [uploadDir(srcDir, dstDir, options) ==> string](#sec-4-2-19)
+ - [downloadDir(srcDir, dstDir, options) ==> string](#sec-4-2-20)
+ - [createReadStream(remotePath, options)) ==> stream object](#sec-4-2-21)
+ - [createWriteStream(remotePath, options) ==> stream object](#sec-4-2-22)
+ - [rcopy(srcPath, dstPath) ==> string](#sec-4-2-23)
+ - [end() ==> boolean](#sec-4-2-24)
+ - [Add and Remove Listeners](#sec-4-2-25)
+- [Platform Quirks & Warnings](#sec-5)
+ - [Server Capabilities](#sec-5-1)
+ - [Issues with `fastPut()` and `fastGet()` Methods](#sec-5-2)
+ - [Promises, Events & Managing Exceptions](#sec-5-3)
+ - [Adding Custom Handlers](#sec-5-3-1)
+ - [Windows Based Servers](#sec-5-4)
+ - [Don't Re-use SftpClient Objects](#sec-5-5)
+- [FAQ](#sec-6)
+ - [Remote server drops connections with only an end event](#sec-6-1)
+ - [How can I pass writeable stream as dst for get method?](#sec-6-2)
+ - [How can I upload files without having to specify a password?](#sec-6-3)
+ - [How can I connect through a Socks Proxy](#sec-6-4)
+ - [Timeout while waiting for handshake or handshake errors](#sec-6-5)
+ - [How can I limit upload/download speed](#sec-6-6)
+ - [Connection hangs or fails for larger files](#sec-6-7)
+- [Examples](#sec-7)
+- [Troubleshooting](#sec-8)
+ - [Common Errors](#sec-8-1)
+ - [Not returning the promise in a `then()` block](#sec-8-1-1)
+ - [Mixing Promise Chains and Async/Await](#sec-8-1-2)
+ - [Try/catch and Error Handlers](#sec-8-1-3)
+ - [Server Differences](#sec-8-1-4)
+ - [Avoid Concurrent Operations](#sec-8-1-5)
+ - [Debugging Support](#sec-8-2)
+- [Logging Issues](#sec-9)
+- [Pull Requests](#sec-10)
+- [Contributors](#sec-11)
+
+
+# Overview
an SFTP client for node.js, a wrapper around [SSH2](https://github.com/mscdex/ssh2) which provides a high level convenience abstraction as well as a Promise based API.
@@ -74,43 +71,40 @@ Code has been tested against Node versions 14.20.0, 16.17.2 and 18.8.0
Node versions < 14.x are not supported.
-
-
-
-## Version 9.x Changes
+## Version 9.x Changes
- Fix bug in `connect()` method when private key data was corrupted. The method was not handling errors fro corrupted ssh private keys and would hang indefinitely without reporting any error. Now reports that it was unable to parse the private key.
- 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.
- 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.
-- 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.
+- 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.
- Changed when event handled flags are reset. Now they are reset after a new set of temporary listeners are added.
-- 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.
+- 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.
- Use nullish coalescing when setting retry parameters instead of or'ing with defaults. Allows setting values to 0.
- **Breaking Change**: This version uses syntax not supported in node versions prior to v14. Therefore, node versions less than v14 will not work.
- **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.
- **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!
-- **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.
-- The `uploadDir()` and `downloadDir()` methods now use asynchrounous processes to upload/download files. This should result in improved performance for these two methods.
-- New Methods: Two new methods, `createWriteStream()` and `createReadStream()` have been added. These methods will return a stream object connected to a remote file on the `sftp` server. Client code is responsible for managing these stream objects. This includes adding any necessary event listeners and disposing of the objects once finished with them.
-- Refactoring of Listeners: The library manages temporary listeners in order to provide a way to catch events and processes them inside a `Promise` context. Previously, every method added its own set of temporary listeners. However, this could result in multiple sets of listeners being added, especially for methods which call other methods as part of their processing e.g. `rmdir(),` `uploadDir()` and `dowqnloadDir()`. To avoid this, *internal only* versions of each method have been created. These internal methods use an *underscore* `_` prefix. Client code should not use these methods directly.
+- **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 used 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 downloading files, otherwise the slower, but more reliable, `get()` method will be used.
+- The `uploadDir()` and `downloadDir()` methods now use asynchronous processes to upload/download files. This should result in improved performance for these two methods.
+- New Methods: Two new methods, `createWriteStream()` and `createReadStream()` have been added. These methods will return a stream object connected to a remote file on the `SFTP` server. Client code is responsible for managing these stream objects. This includes adding any necessary event listeners and disposing of the objects once finished with them.
+- Re-factoring of Listeners: The library manages temporary listeners in order to provide a way to catch events and processes them inside a `Promise` context. Previously, every method added its own set of temporary listeners. However, this could result in multiple sets of listeners being added, especially for methods which call other methods as part of their processing e.g. `rmdir(),` `uploadDir()` and `dowqnloadDir()`. To avoid this, *internal only* versions of each method have been created. These internal methods use an *underscore* `_` prefix. Client code should not use these methods directly.
- New method: Added `rcopy()` method to perform a remote copy of a file on the remote SFTP server.
- Bumped ssh2 version to 1.11.0
+# Installation
-
+```shell
-# Installation
+npm
-```shell
npm install ssh2-sftp-client
```
+# Basic Usage
-
+```javascript
-# Basic Usage
+let
-```javascript
let Client = require('ssh2-sftp-client');
let sftp = new Client();
@@ -128,19 +122,13 @@ sftp.connect({
});
```
-
-
-
-# Documentation
+# Documentation
The connection options are the same as those offered by the underlying SSH2 module. For full details, please see [SSH2 client methods](https://github.com/mscdex/ssh2#user-content-client-methods)
All the methods will return a Promise, except for `on()` and `removeListener()`, which are typically only used in special use cases.
-
-
-
-## Specifying Paths
+## Specifying Paths
The convention with both FTP and SFTP is that paths are specified using a 'nix' style i.e. use `/` as the path separator. This means that even if your SFTP server is running on a win32 platform, you should use `/` instead of `\` as the path separator. For example, for a win32 path of `C:\Users\fred` you would actually use `/C:/Users/fred`. If your win32 server does not support the 'nix' path convention, you can try setting the `remotePathSep` property of the `SftpClient` object to the path separator of your remote server. This **might** work, but has not been tested. Please let me know if you need to do this and provide details of the SFTP server so that I can try to create an appropriate environment and adjust things as necessary. At this point, I'm not aware of any win32 based SFTP servers which do not support the 'nix' path convention.
@@ -150,35 +138,38 @@ It is important to recognise that the current remote directory may not always be
There is a small performance hit for using `./` and `../` as the module must query the remote server to determine what the root path is and derive the absolute path. Using absolute paths are therefore more efficient and likely more robust.
-When specifying file paths, ensure to include a full path i.e. include the remote filename. Don't expect the module to append the local file name to the path you provide. For example, the following will not work
+When specifying file paths, ensure to include a full path i.e. include the remote file name. Don't expect the module to append the local file name to the path you provide. For example, the following will not work
```javascript
+
+
+
client.put('/home/fred/test.txt', '/remote/dir');
```
-will not result in the file `test.txt` being copied to `/remote/dir/test.txt`. You need to specify the target filename as well e.g.
+will not result in the file `test.txt` being copied to `/remote/dir/test.txt`. You need to specify the target file name as well e.g.
```javascript
+
+
+
client.put('/home/fred/test.txt', '/remote/dir/test.txt');
```
Note that the remote file name does not have to be the same as the local file name. The following works fine;
```javascript
-client.put('/home/fred/test.txt', '/remote/dir/test-copy.txt');
-```
-
-This will copy the local file `test.txt` to the remote file `test-copy.txt` in the directory `/remote/dir`.
-
-## Methods
+client.put('/home/fred/test.txt', '/remote/dir/test-copy.txt');
+```
+This will copy the local file `test.txt` to the remote file `test-copy.txt` in the directory `/remote/dir`.
-
+## Methods
-### new SftpClient(name) ===> SFTP client object
+### new SftpClient(name) ===> SFTP client object
Constructor to create a new `ssh2-sftp-client` object. An optional `name` string can be provided, which will be used in error messages to help identify which client has thrown the error.
@@ -189,6 +180,9 @@ Constructor to create a new `ssh2-sftp-client` object. An optional `name` string
2. Example Use
```javascript
+
+ 'use
+
'use strict';
const Client = require('ssh2-sftp-client');
@@ -214,10 +208,7 @@ Constructor to create a new `ssh2-sftp-client` object. An optional `name` string
});
```
-
-
-
-### connect(config) ===> SFTP object
+### connect(config) ===> SFTP object
Connect to an sftp server. Full documentation for connection options is available [here](https://github.com/mscdex/ssh2#user-content-client-methods)
@@ -228,6 +219,9 @@ Connect to an sftp server. Full documentation for connection options is availabl
The `retries`, `retry_factor` and `retry_minTimeout` options are not part of the SSH2 module. These are part of the configuration for the [retry](https://www.npmjs.com/package/retry) package and what is used to enable retrying of sftp connection attempts. See the documentation for that package for an explanation of these values.
```javascript
+
+ //
+
// common options
let commonOpts {
@@ -272,6 +266,10 @@ Connect to an sftp server. Full documentation for connection options is availabl
2. Example Use
```javascript
+
+ sftp.connect({
+
+
sftp.connect({
host: example.com,
port: 22,
@@ -280,10 +278,7 @@ Connect to an sftp server. Full documentation for connection options is availabl
});
```
-
-
-
-### list(path, filter) ==> Array[object]
+### list(path, filter) ==> Array[object]
Retrieves a directory listing. This method returns a Promise, which once realised, returns an array of objects representing items in the remote directory.
@@ -293,6 +288,9 @@ Retrieves a directory listing. This method returns a Promise, which once realise
1. Example Use
```javascript
+
+ const
+
const Client = require('ssh2-sftp-client');
const config = {
@@ -323,34 +321,24 @@ Retrieves a directory listing. This method returns a Promise, which once realise
The objects in the array returned by `list()` have the following properties;
- ```javascript
- {
- type: // file type(-, d, l)
- name: // file name
- size: // file size
- modifyTime: // file timestamp of modified time
- accessTime: // file timestamp of access time
- rights: {
- user:
- group:
- other:
- },
- owner: // user ID
- group: // group ID
- longname: // like ls -l line
- }
+ ```nillangnilswitchesnilflags
+ nilbody
+ #+END_SRC
+
+ ***
+ nilbody
```
-
-
-
-### exists(path) ==> boolean
+### exists(path) ==> boolean
Tests to see if remote file or directory exists. Returns type of remote object if it exists or false if it does not.
1. Example Use
```javascript
+
+ const
+
const Client = require('ssh2-sftp-client');
const config = {
@@ -377,10 +365,7 @@ Tests to see if remote file or directory exists. Returns type of remote object i
});
```
-
-
-
-### stat(path) ==> object
+### stat(path) ==> object
Returns the attributes associated with the object pointed to by `path`.
@@ -391,6 +376,9 @@ Returns the attributes associated with the object pointed to by `path`.
The `stat()` method returns an object with the following properties;
```javascript
+
+ let
+
let stats = {
mode: 33279, // integer representing type and permissions
uid: 1000, // user ID
@@ -411,6 +399,9 @@ Returns the attributes associated with the object pointed to by `path`.
2. Example Use
```javascript
+
+ let
+
let client = new Client();
client.connect(config)
@@ -428,10 +419,7 @@ Returns the attributes associated with the object pointed to by `path`.
});
```
-
-
-
-### get(path, dst, options) ==> String|Stream|Buffer
+### get(path, dst, options) ==> String|Stream|Buffer
Retrieve a file from a remote SFTP server. The `dst` argument defines the destination and can be either a string, a stream object or undefined. If it is a string, it is interpreted as the path to a location on the local file system (path should include the file name). If it is a stream object, the remote data is passed to it via a call to pipe(). If `dst` is undefined, the method will put the data into a buffer and return that buffer when the Promise is resolved. If `dst` is defined, it is returned when the Promise is resolved.
@@ -446,6 +434,9 @@ In general, if you're going to pass in a string as the destination, you are bett
The `options` argument can be used to pass options to the underlying streams and pipe call used by this method. The argument is an object with three possible properties, `readStreamOptions`, `writeStreamOptions` and `pipeOptions`. The values for each of these properties should be an object containing the required options. For example, possible read stream and pipe options could be defined as
```javascript
+
+ let
+
let options = {
readStreamOptions: {
flags: 'r',
@@ -465,6 +456,9 @@ In general, if you're going to pass in a string as the destination, you are bett
2. Example Use
```javascript
+
+ let
+
let client = new Client();
let remotePath = '/remote/server/path/file.txt';
@@ -484,10 +478,7 @@ In general, if you're going to pass in a string as the destination, you are bett
- **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'.
-
-
-
-### fastGet(remotePath, localPath, options) ===> string
+### fastGet(remotePath, localPath, options) ===> string
Downloads a file at remotePath to localPath using parallel reads for faster throughput. This is the simplest method if you just want to download a file.
@@ -497,13 +488,12 @@ Downloads a file at remotePath to localPath using parallel reads for faster thro
1. Options
- ```javascript
- {
- concurrency: 64, // integer. Number of concurrent reads to use
- chunkSize: 32768, // integer. Size of each read in bytes
- step: function(total_transferred, chunk, total) // callback called each time a
- // chunk is transferred
- }
+ ```nillangnilswitchesnilflags
+ nilbody
+ #+END_SRC
+
+ -
+ nilbody
```
- **Warning:** Some servers do not respond correctly to requests to alter chunk size. This can result in lost or corrupted data.
@@ -511,6 +501,9 @@ Downloads a file at remotePath to localPath using parallel reads for faster thro
2. Sample Use
```javascript
+
+ let
+
let client = new Client();
let remotePath = '/server/path/file.txt';
let localPath = '/local/path/file.txt';
@@ -527,10 +520,7 @@ Downloads a file at remotePath to localPath using parallel reads for faster thro
});
```
-
-
-
-### put(src, remotePath, options) ==> string
+### put(src, remotePath, options) ==> string
Upload data from local system to remote server. If the `src` argument is a string, it is interpreted as a local file path to be used for the data to transfer. If the `src` argument is a buffer, the contents of the buffer are copied to the remote file and if it is a readable stream, the contents of that stream are piped to the `remotePath` on the server.
@@ -542,13 +532,12 @@ Upload data from local system to remote server. If the `src` argument is a strin
The options object supports three properties, `readStreamOptions`, `writeStreamOptions` and `pipeOptions`. The value for each property should be an object with options as properties and their associated values representing the option value. For example, you might use the following to set `writeStream` options.
- ```javascript
- {
- writeStreamOptions: {
- flags: 'w', // w - write and a - append
- encoding: null, // use null for binary files
- mode: 0o666, // mode to use for created file (rwx)
- }}
+ ```nillangnilswitchesnilflags
+ nilbody
+ #+END_SRC
+
+ The
+ nilbody
```
The most common options to use are mode and encoding. The values shown above are the defaults. You do not have to set encoding to utf-8 for text files, null is fine for all file types. However, using utf-8 encoding for binary files will often result in data corruption.
@@ -558,6 +547,9 @@ Upload data from local system to remote server. If the `src` argument is a strin
2. Example Use
```javascript
+
+ let
+
let client = new Client();
let data = fs.createReadStream('/path/to/local/file.txt');
@@ -577,10 +569,7 @@ Upload data from local system to remote server. If the `src` argument is a strin
- **Tip:** If the src argument is a path string, consider just using `fastPut()`.
-
-
-
-### fastPut(localPath, remotePath, options) ==> string
+### fastPut(localPath, remotePath, options) ==> string
Uploads the data in file at `localPath` to a new file on remote server at `remotePath` using concurrency. The options object allows tweaking of the fast put process.
@@ -590,14 +579,12 @@ Uploads the data in file at `localPath` to a new file on remote server at `remot
1. Options
- ```javascript
- {
- concurrency: 64, // integer. Number of concurrent reads
- chunkSize: 32768, // integer. Size of each read in bytes
- mode: 0o755, // mixed. Integer or string representing the file mode to set
- step: function(total_transferred, chunk, total) // function. Called every time
- // a part of a file was transferred
- }
+ ```nillangnilswitchesnilflags
+ nilbody
+ #+END_SRC
+
+ -
+ nilbody
```
- **Warning:** There have been reports that some SFTP servers will not honour requests for non-default chunk sizes. This can result in data loss or corruption.
@@ -605,6 +592,9 @@ Uploads the data in file at `localPath` to a new file on remote server at `remot
2. Example Use
```javascript
+
+ let
+
let localFile = '/path/to/file.txt';
let remoteFile = '/path/to/remote/file.txt';
let client = new Client();
@@ -621,10 +611,7 @@ Uploads the data in file at `localPath` to a new file on remote server at `remot
});
```
-
-
-
-### append(input, remotePath, options) ==> string
+### append(input, remotePath, options) ==> string
Append the `input` data to an existing remote file. There is no integrity checking performed apart from normal writeStream checks. This function simply opens a writeStream on the remote file in append mode and writes the data passed in to the file.
@@ -636,13 +623,12 @@ Append the `input` data to an existing remote file. There is no integrity checki
The following options are supported;
- ```javascript
- {
- flags: 'a', // w - write and a - append
- encoding: null, // use null for binary files
- mode: 0o666, // mode to use for created file (rwx)
- autoClose: true // automatically close the write stream when finished
- }
+ ```nillangnilswitchesnilflags
+ nilbody
+ #+END_SRC
+
+ The
+ nilbody
```
The most common options to use are mode and encoding. The values shown above are the defaults. You do not have to set encoding to utf-8 for text files, null is fine for all file types. Generally, I would not attempt to append binary files.
@@ -650,6 +636,9 @@ Append the `input` data to an existing remote file. There is no integrity checki
2. Example Use
```javascript
+
+ let
+
let remotePath = '/path/to/remote/file.txt';
let client = new Client();
@@ -665,10 +654,7 @@ Append the `input` data to an existing remote file. There is no integrity checki
});
```
-
-
-
-### mkdir(path, recursive) ==> string
+### mkdir(path, recursive) ==> string
Create a new directory. If the recursive flag is set to true, the method will create any directories in the path which do not already exist. Recursive flag defaults to false.
@@ -678,6 +664,9 @@ Create a new directory. If the recursive flag is set to true, the method will cr
1. Example Use
```javascript
+
+ let
+
let remoteDir = '/path/to/new/dir';
let client = new Client();
@@ -693,10 +682,7 @@ Create a new directory. If the recursive flag is set to true, the method will cr
});
```
-
-
-
-### rmdir(path, recursive) ==> string
+### rmdir(path, recursive) ==> string
Remove a directory. If removing a directory and recursive flag is set to `true`, the specified directory and all sub-directories and files will be deleted. If set to false and the directory has sub-directories or files, the action will fail.
@@ -708,6 +694,9 @@ Remove a directory. If removing a directory and recursive flag is set to `true`,
1. Example Use
```javascript
+
+ let
+
let remoteDir = '/path/to/remote/dir';
let client = new Client();
@@ -723,10 +712,7 @@ Remove a directory. If removing a directory and recursive flag is set to `true`,
});
```
-
-
-
-### delete(path, noErrorOK) ==> string
+### delete(path, noErrorOK) ==> string
Delete a file on the remote server.
@@ -737,6 +723,9 @@ Delete a file on the remote server.
1. Example Use
```javascript
+
+ let
+
let remoteFile = '/path/to/remote/file.txt';
let client = new Client();
@@ -752,10 +741,7 @@ Delete a file on the remote server.
});
```
-
-
-
-### rename(fromPath, toPath) ==> string
+### rename(fromPath, toPath) ==> string
Rename a file or directory from `fromPath` to `toPath`. You must have the necessary permissions to modify the remote file.
@@ -765,6 +751,9 @@ Rename a file or directory from `fromPath` to `toPath`. You must have the necess
1. Example Use
```javascript
+
+ let
+
let from = '/remote/path/to/old.txt';
let to = '/remote/path/to/new.txt';
let client = new Client();
@@ -781,17 +770,17 @@ Rename a file or directory from `fromPath` to `toPath`. You must have the necess
});
```
+### posixRename(fromPath, toPath) ==> string
-
-
-### posixRename(fromPath, toPath) ==> string
-
-This method uses the openssh POSIX rename extension introduced in OpenSSH 4.8. The advantage of this version of rename over standard SFTP rename is that it is an atomic operation and will allow renaming a resource where the destination name exists. The POSIX rename will also work on some filesystems which do not support standard SFTP rename because they don't support the system hardlink() call. The POSIX rename extension is available on all openSSH servers from 4.8 and some other implementations. This is an extension to the standard SFTP protocol and therefore is not supported on all sSFTP servers.
+This method uses the openssh POSIX rename extension introduced in OpenSSH 4.8. The advantage of this version of rename over standard SFTP rename is that it is an atomic operation and will allow renaming a resource where the destination name exists. The POSIX rename will also work on some file systems which do not support standard SFTP rename because they don't support the system hardlink() call. The POSIX rename extension is available on all openSSH servers from 4.8 and some other implementations. This is an extension to the standard SFTP protocol and therefore is not supported on all sftp servers.
- **fromPath:** string. Path to existing file to be renamed.
- **toPath:** string. Path for new name. If it already exists, it will be replaced by file specified in fromPath
```javascript
+
+let
+
let from = '/remote/path/to/old.txt';
let to = '/remote/path/to/new.txt';
let client = new Client();
@@ -808,10 +797,7 @@ client.connect(config)
});
```
-
-
-
-### chmod(path, mode) ==> string
+### chmod(path, mode) ==> string
Change the mode (read, write or execute permissions) of a remote file or directory.
@@ -821,6 +807,9 @@ Change the mode (read, write or execute permissions) of a remote file or directo
1. Example Use
```javascript
+
+ let
+
let path = '/path/to/remote/file.txt';
let newMode = 0o644; // rw-r-r
let client = new Client();
@@ -837,10 +826,7 @@ Change the mode (read, write or execute permissions) of a remote file or directo
});
```
-
-
-
-### realPath(path) ===> string
+### realPath(path) ===> string
Converts a relative path to an absolute path on the remote server. This method is mainly used internally to resolve remote path names.
@@ -848,17 +834,11 @@ Converts a relative path to an absolute path on the remote server. This method i
- **path:** A file path, either relative or absolute. Can handle '.' and '..', but does not expand '~'.
-
-
-
-### cwd() ==> string
+### cwd() ==> string
Returns what the server believes is the current remote working directory.
-
-
-
-### uploadDir(srcDir, dstDir, options) ==> string
+### uploadDir(srcDir, dstDir, options) ==> string
Upload the directory specified by `srcDir` to the remote directory specified by `dstDir`. The `dstDir` will be created if necessary. Any sub directories within `srcDir` will also be uploaded. Any existing files in the remote path will be overwritten.
@@ -877,61 +857,61 @@ The `useFastput` option is a boolean option. If `true`, the method will use the
1. Example
```javascript
- 'use strict';
- // Example of using the uploadDir() method to upload a directory
- // to a remote SFTP server
- const path = require('path');
- const SftpClient = require('../src/index');
- const dotenvPath = path.join(__dirname, '..', '.env');
- require('dotenv').config({path: dotenvPath});
+ 'use strict';
- const config = {
- host: process.env.SFTP_SERVER,
- username: process.env.SFTP_USER,
- password: process.env.SFTP_PASSWORD,
- port: process.env.SFTP_PORT || 22
- };
+ // Example of using the uploadDir() method to upload a directory
+ // to a remote SFTP server
- async function main() {
- const client = new SftpClient('upload-test');
- const src = path.join(__dirname, '..', 'test', 'testData', 'upload-src');
- const dst = '/home/tim/upload-test';
+ const path = require('path');
+ const SftpClient = require('../src/index');
- try {
- await client.connect(config);
- client.on('upload', info => {
- console.log(`Listener: Uploaded ${info.source}`);
- });
- let rslt = await client.uploadDir(src, dst);
- return rslt;
- } catch (err) {
- console.error(err);
- } finally {
- client.end();
- }
- }
+ const dotenvPath = path.join(__dirname, '..', '.env');
+ require('dotenv').config({path: dotenvPath});
- main()
- .then(msg => {
- console.log(msg);
- })
- .catch(err => {
- console.log(`main error: ${err.message}`);
- });
+ const config = {
+ host: process.env.SFTP_SERVER,
+ username: process.env.SFTP_USER,
+ password: process.env.SFTP_PASSWORD,
+ port: process.env.SFTP_PORT || 22
+ };
+
+ async function main() {
+ const client = new SftpClient('upload-test');
+ const src = path.join(__dirname, '..', 'test', 'testData', 'upload-src');
+ const dst = '/home/tim/upload-test';
+
+ try {
+ await client.connect(config);
+ client.on('upload', info => {
+ console.log(`Listener: Uploaded ${info.source}`);
+ });
+ let rslt = await client.uploadDir(src, dst);
+ return rslt;
+ } catch (err) {
+ console.error(err);
+ } finally {
+ client.end();
+ }
+ }
+
+ main()
+ .then(msg => {
+ console.log(msg);
+ })
+ .catch(err => {
+ console.log(`main error: ${err.message}`);
+ });
```
-
-
-
-### downloadDir(srcDir, dstDir, options) ==> string
+### downloadDir(srcDir, dstDir, options) ==> string
Download the remote directory specified by `srcDir` to the local file system directory specified by `dstDir`. The `dstDir` directory will be created if required. All sub directories within `srcDir` will also be copied. Any existing files in the local path will be overwritten. No files in the local path will be deleted.
-The method also emites `download` events to provide a way to monitor download progress. The download event listener is called with one argument, an object with two properties, source and destination. The source property is the path to the remote file that has been downloaded and the destination is the local path to where the file was downloaded to. You can add a listener for this event using the `on()` method.
+The method also emits `download` events to provide a way to monitor download progress. The download event listener is called with one argument, an object with two properties, source and destination. The source property is the path to the remote file that has been downloaded and the destination is the local path to where the file was downloaded to. You can add a listener for this event using the `on()` method.
The `options` argument is an options object with two supported properties, `filter` and `useFastget`. The `filter` argument is a predicate function which will be called with two arguments for each potential item to be downloaded. The first argument is the full path of the item and the second argument is a boolean, which will be true if the item is a directory. If the function returns true, the item will be included in the download. If it returns false, it will be filtered and ignored. The filter function is called via the `Array.filter` method. These array comprehension methods are known to be unsafe for asynchronous functions. Therefore, only synchronous filter functions are supported at this time.
@@ -939,11 +919,14 @@ If the `useFastget` property is set to `true`, the method will use `fastGet()` t
- **srcDir:** A remote file path specified as a string
- **dstDir:** A local file path specified as a string
-- **options:** An object with two supported properties, `filter` and `useFastget`. The filter property is a function accepting two arguments, the full path to an item and a boolean value which will be true if the item is a directory. The function is called for each item in the download path and should return true to include the item and false to exclude it in the download. The `useFastget` property is a boolean. If true, the `fastGet()` method will be used to transfer files. If `false` (the default), the slower but better supported `get()` mehtod is used. .
+- **options:** An object with two supported properties, `filter` and `useFastget`. The filter property is a function accepting two arguments, the full path to an item and a boolean value which will be true if the item is a directory. The function is called for each item in the download path and should return true to include the item and false to exclude it in the download. The `useFastget` property is a boolean. If true, the `fastGet()` method will be used to transfer files. If `false` (the default), the slower but better supported `get()` method is used. .
1. Example
```javascript
+
+ 'use
+
'use strict';
// Example of using the downloadDir() method to upload a directory
@@ -989,10 +972,7 @@ If the `useFastget` property is set to `true`, the method will use `fastGet()` t
```
-
-
-
-### createReadStream(remotePath, options)) ==> stream object
+### createReadStream(remotePath, options)) ==> stream object
Returns a read stream object which is attached to the remote file specified by the `remotePath` argument. This is a low level method which just returns a read stream object. Client code is fully responsible for managing and releasing the resources associated with the stream once finished i.e. closing files, removing listeners etc.
@@ -1004,43 +984,37 @@ Returns a read stream object which is attached to the remote file specified by t
- **mode:** 0o666
- **autoClose:** defaults to true. If set to false, client code is responsible for closing file descriptors when finished
- **start:** Default 0. Position to start reading bytes from (inclusive)
- - **end:** Postion to stop reading bytes (inclusive).
+ - **end:** Position to stop reading bytes (inclusive).
+### createWriteStream(remotePath, options) ==> stream object
-
-
-### createWriteStream(remotePath, options) ==> stream object
-
-Returns a write stream object which is attached to the remote file specified in the `remotePath` argument. This is a low legvel function which just returns the stream object. Client code is fully responsible for managing that object, including closing any file descriptiors and removing listeners etc.
+Returns a write stream object which is attached to the remote file specified in the `remotePath` argument. This is a low level function which just returns the stream object. Client code is fully responsible for managing that object, including closing any file descriptors and removing listeners etc.
- **remotePath:** Path to the remote file specified as a string
- **options:** An object containing stream options. Supported properties include
- **flags:** default 'w'
- - **encoding:** defulat null
+ - **encoding:** default null
- **mode:** 0o666
- **autoClose:** true
- **start:** Byte position to start writing from (inclusive). May require changing flag to 'r+'.
+### rcopy(srcPath, dstPath) ==> string
-
-
-### rcopy(srcPath, dstPath) ==> string
-
-Perfrom a remote file copy. The file identified by the `srcPath` argument will be copied to the file specified as the `dstPath` argument. The directory where `dstPath` will be placed must exist, but the actual file must not i.e. no overwrites allowed.
+Perform a remote file copy. The file identified by the `srcPath` argument will be copied to the file specified as the `dstPath` argument. The directory where `dstPath` will be placed must exist, but the actual file must not i.e. no overwrites allowed.
- **srcPath:** Path to remote file to be copied specified as a string
-- **dstPath:** Path to where the copy will be creaeted specified as a string
+- **dstPath:** Path to where the copy will be created specified as a string
-
-
-
-### end() ==> boolean
+### end() ==> boolean
Ends the current client session, releasing the client socket and associated resources. This function also removes all listeners associated with the client.
1. Example Use
```javascript
+
+ let
+
let client = new Client();
client.connect(config)
@@ -1055,10 +1029,7 @@ Ends the current client session, releasing the client socket and associated reso
});
```
-
-
-
-### Add and Remove Listeners
+### Add and Remove Listeners
Although normally not required, you can add and remove custom listeners on the ssh2 client object. This object supports a number of events, but only a few of them have any meaning in the context of SFTP. These are
@@ -1076,82 +1047,55 @@ Although normally not required, you can add and remove custom listeners on the s
Removes the specified listener from the event specified in eventType. Note that the `end()` method automatically removes all listeners from the client object.
+# Platform Quirks & Warnings
-
-
-# Platform Quirks & Warnings
-
+## Server Capabilities
-
-
-## Server Capabilities
-
-All SFTP servers and platforms are not equal. Some facilities provided by `ssh2-sftp-client` either depend on capabilities of the remote server or the underlying capabilities of the remote server platform. As an example, consider `chmod()`. This command depends on a remote filesystem which implements the 'nix' concept of users and groups. The *win32* platform does not have the same concept of users and groups, so `chmod()` will not behave in the same way.
+All SFTP servers and platforms are not equal. Some facilities provided by `ssh2-sftp-client` either depend on capabilities of the remote server or the underlying capabilities of the remote server platform. As an example, consider `chmod()`. This command depends on a remote file system which implements the 'nix' concept of users and groups. The *win32* platform does not have the same concept of users and groups, so `chmod()` will not behave in the same way.
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.
+## Issues with `fastPut()` and `fastGet()` Methods
-
-
-## Issues with `fastPut()` and `fastGet()` Methods
-
-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.
+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 specific packet size.
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.
-
-
-
-## Promises, Events & Managing Exceptions
+## Promises, Events & Managing Exceptions
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.
-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.
+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 example 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.
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.
-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.
+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` method 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.
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.
-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.
+The other area where additional events are fired is during the end() call. To deal with these events, the `end()` method sets 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.
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.
-
-
-
-### Adding Custom Handlers
+### Adding Custom Handlers
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.
-
-
-
-## Windows Based Servers
+## Windows Based Servers
It appears that when the sftp server is running on Windows, a *ECONNRESET* error signal is raised when the end() method is called. Unfortunately, this signal is raised after a considerable delay. This means we cannot remove the error handler used in the end() promise as otherwise you will get an uncaught exception error. Leaving the handler in place, even though we will ignore this error, solves that issue, but unfortunately introduces a new problem. Because we are not removing the listener, if you re-use the client object for subsequent connections, an additional error handler will be added. If this happens more than 11 times, you will eventually see the Node warning about a possible memory leak. This is because node monitors the number of error handlers and if it sees more than 11 added to an object, it assumes there is a problem and generates the warning.
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.
-
-
-
-## Don't Re-use SftpClient Objects
+## Don't Re-use SftpClient Objects
Due to an issue with *ECONNRESET* error signals when connecting to Windows based SFTP servers, it is not possible to remove the error handler in the end() method. This means that if you re-use the SftpClient object for multiple connections e.g. calling connect(), then end(), then connect() etc, you run the risk of multiple error handlers being added to the SftpClient object. After 11 handlers have been added, Node will generate a possible memory leak warning.
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.
+# FAQ
-
-
-# FAQ
-
-
-
-
-## Remote server drops connections with only an end event
+## Remote server drops connections with only an end event
Many SFTP servers have rate limiting protection which will drop connections once a limit has been reached. In particular, openSSH has the setting `MaxStartups`, which can be a tuple of the form `max:drop:full` where `max` is the maximum allowed unauthenticated connections, `drop` is a percentage value which specifies percentage of connections to be dropped once `max` connections has been reached and `full` is the number of connections at which point all subsequent connections will be dropped. e.g. `10:30:60` means allow up to 10 unauthenticated connections after which drop 30% of connection attempts until reaching 60 unauthenticated connections, at which time, drop all attempts.
@@ -1159,16 +1103,16 @@ Clients first make an unauthenticated connection to the SFTP server to begin neg
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.
-
-
-
-## How can I pass writable stream as dst for get method?
+## How can I pass writeable stream as dst for get method?
If the dst argument passed to the get method is a writeable stream, the remote file will be piped into that writeable. If the writeable you pass in is a writeable stream created with `fs.createWriteStream()`, the data will be written to the file specified in the constructor call to `createWriteStream()`.
The writeable stream can be any type of write stream. For example, the below code will convert all the characters in the remote file to upper case before it is saved to the local file system. This could just as easily be something like a gunzip stream from `zlib`, enabling you to decompress remote zipped files as you bring them across before saving to local file system.
```javascript
+
+'use
+
'use strict';
// Example of using a writeable with get to retrieve a file.
@@ -1218,16 +1162,16 @@ sftp
});
```
-
-
-
-## How can I upload files without having to specify a password?
+## How can I upload files without having to specify a password?
There are a couple of ways to do this. Essentially, you want to setup SSH keys and use these for authentication to the remote server.
One solution, provided by @KalleVuorjoki is to use the SSH agent process. **Note**: SSHAUTHSOCK is normally created by your OS when you load the ssh-agent as part of the login session.
```javascript
+
+let
+
let sftp = new Client();
sftp.connect({
host: 'YOUR-HOST',
@@ -1242,6 +1186,9 @@ sftp.connect({
Another alternative is to just pass in the SSH key directly as part of the configuration.
```javascript
+
+let
+
let sftp = new Client();
sftp.connect({
host: 'YOUR-HOST',
@@ -1253,14 +1200,14 @@ sftp.connect({
}
```
-
-
-
-## How can I connect through a Socks Proxy
+## How can I connect through a Socks Proxy
This solution was provided by @jmorino.
```javascript
+
+import
+
import { SocksClient } from 'socks';
import SFTPClient from 'ssh2-sftp-client';
@@ -1289,59 +1236,59 @@ client.connect({
// client is connected
```
+## Timeout while waiting for handshake or handshake errors
-
+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.
-## Timeout while waiting for handshake or handshake errors
+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.
-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.
+## How can I limit upload/download speed
-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.
+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.
+```javascript
-
-## How can I limit upload/download speed
-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.
-```javascript
-const Throttle = require('throttle');
-const progress = require('progress-stream');
-// limit download speed
-const throttleStream = new Throttle(config.throttle);
-// download progress stream
-const progressStream = progress({
- length: fileSize,
- time: 500,
-});
-progressStream.on('progress', (progress) => {
- console.log(progress.percentage.toFixed(2));
-});
-const outStream = createWriteStream(localPath);
-// pipe streams together
-throttleStream.pipe(progressStream).pipe(outStream);
-try {
- // set autoClose to false
- await client.get(remotePath, throttleStream, { autoClose: false });
-} catch (e) {
- console.log('sftp error', e);
-} finally {
- await client.end();
-}
-```
+ const Throttle = require('throttle');
+ const progress = require('progress-stream');
+
+ // limit download speed
+ const throttleStream = new Throttle(config.throttle);
+
+ // download progress stream
+ const progressStream = progress({
+ length: fileSize,
+ time: 500,
+ });
+ progressStream.on('progress', (progress) => {
+ console.log(progress.percentage.toFixed(2));
+ });
+ const outStream = createWriteStream(localPath);
-
+ // pipe streams together
+ throttleStream.pipe(progressStream).pipe(outStream);
-## Connection hangs or fails for larger files
+ try {
+ // set autoClose to false
+ await client.get(remotePath, throttleStream, { autoClose: false });
+ } catch (e) {
+ console.log('sftp error', e);
+ } finally {
+ await client.end();
+ }
+```
+
+## Connection hangs or fails for larger files
This was contributed by Ladislav Jacho. Thanks.
@@ -1349,17 +1296,11 @@ A symptom of this issue is that you are able to upload small files, but uploadin
For more explanation, see [issue #342](https://github.com/theophilusx/ssh2-sftp-client/issues/342).
-
-
-
-# Examples
+# Examples
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.
-
-
-
-# Troubleshooting
+# Troubleshooting
The `ssh2-sftp-client` module is essentially a wrapper around the `ssh2` and `ssh2-streams` modules, providing a higher level `promise` based API. When you run into issues, it is important to try and determine where the issue lies - either in the ssh2-sftp-client module or the underlying `ssh2` and `ssh2-streams` modules. One way to do this is to first identify a minimal reproducible example which reproduces the issue. Once you have that, try to replicate the functionality just using the `ssh2` and `ssh2-streams` modules. If the issue still occurs, then you can be fairly confident it is something related to those later 2 modules and therefore and issue which should be referred to the maintainer of that module.
@@ -1371,21 +1312,18 @@ Note also that in the repository there are two useful directories. The first is
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.
+## Common Errors
-
+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.
-## Common Errors
-
-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.
+### Not returning the promise in a `then()` block
+All methods in `ssh2-sftp-client` return a Promise. This means methods are executed *asynchrnously*. When you call a method inside the `then()` block of a promise chain, it is critical that you return the Promise that call generates. Failing to do this will result in the `then()` block completing and your code starting execution of the next `then()`, `catch()` or `finally()` block before your promise has been fulfilled. For example, the following will not do what you expect
-
+```javascript
-### Not returning the promise in a `then()` block
-All methods in `ssh2-sftp-client` return a Promise. This means methods are executed *asynchrnously*. When you call a method inside the `then()` block of a promise chain, it is critical that you return the Promise that call generates. Failing to do this will result in the `then()` block completing and your code starting execution of the next `then()`, `catch()` or `finally()` block before your promise has been fulfilled. For example, the following will not do what you expect
-```javascript
sftp.connect(config)
.then(() => {
sftp.fastGet('foo.txt', 'bar.txt');
@@ -1400,6 +1338,9 @@ sftp.connect(config)
In the above code, the `sftp.end()` method will almost certainly be called before `sftp.fastGet()` has been fulfilled (unless the *foo.txt* file is really small!). In fact, the whole promise chain will complete and exit even before the `sftp.end()` call has been fulfilled. The correct code would be something like
```javascript
+
+
+
sftp.connect(config)
.then(() => {
return sftp.fastGet('foo.txt', 'bar.txt');
@@ -1415,14 +1356,14 @@ Note the `return` statements. These ensure that the Promise returned by the clie
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.
-
-
-
-### Mixing Promise Chains and Async/Await
+### Mixing Promise Chains and Async/Await
Another common error is to mix Promise chains and async/await calls. This is rarely a great idea. While you can do this, it tends to create complicated and difficult to maintain code. Select one approach and stick with it. Both approaches are functionally equivalent, so there is no reason to mix up the two paradigms. My personal preference would be to use async/await as I think that is more *natural* for most developers. For example, the following is more complex and difficult to follow than necessary (and has a bug!)
```javascript
+
+
+
sftp.connect(config)
.then(() => {
return sftp.cwd();
@@ -1445,6 +1386,9 @@ The main bug in the above code is the `then()` block is not returning the Promis
Using async/await inside the promise chain has created unnecessary complexity and leads to incorrect assumptions regarding how the code will execute. A quick glance at the code is likely to give the impression that execution will wait for the `sftp.fastGet()` call to be fulfilled before continuing. This is not the case. The code would be more clearly expressed as either
```javascript
+
+
+
sftp.connect(config)
.then(() => {
return sftp.cwd();
@@ -1461,6 +1405,9 @@ sftp.connect(config)
**or, using async/await**
```javascript
+
+
+
async function doSftp() {
try {
let sftp = await sftp.connect(conf);
@@ -1475,41 +1422,32 @@ async function doSftp() {
}
```
-
-
-
-### Try/catch and Error Handlers
+### Try/catch and Error Handlers
Another common error is to try and use a try/catch block to catch event signals, such as an error event. In general, you cannot use try/catch blocks for asynchronous code and expect errors to be caught by the `catch` block. Handling errors in asynchronous code is one of the key reasons we now have the Promise and async/await frameworks.
-The basic problem is that the try/catch block will have completed execution before the asynchronous code has completed. If the asynchronous code has not compleed, then there is a potential for it to raise an error. However, as the try/catch block has already completed, there is no *catch* waiting to catch the error. It will bubble up and probably result in your script exiting with an uncaught exception error.
+The basic problem is that the try/catch block will have completed execution before the asynchronous code has completed. If the asynchronous code has not completed, then there is a potential for it to raise an error. However, as the try/catch block has already completed, there is no *catch* waiting to catch the error. It will bubble up and probably result in your script exiting with an uncaught exception error.
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.
-
-
-
-### Server Differences
+### Server Differences
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.
-
-
-
-### Avoid Concurrent Operations
+### Avoid Concurrent Operations
Technically, SFTP should be able to perform multiple operations concurrently. As node is single threaded, what we a really talking about is running multiple execution contexts as a pool where node will switch contexts when each context is blocked due to things like waiting on network data etc. However, I have found this to be extremely unreliable and of very little benefit from a performance perspective. My recommendation is to therefore avoid executing multiple requests over the same connection in parallel (for example, generating multiple `get()` promises and using something like `Promise.all()` to resolve them.
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.
-
-
-
-## Debugging Support
+## Debugging Support
You can add a `debug` property to the config object passed in to `connect()` to turn on debugging. This will generate quite a lot of output. The value of the property should be a function which accepts a single string argument. For example;
```javascript
+
+config.debug
+
config.debug = msg => {
console.error(msg);
};
@@ -1519,26 +1457,23 @@ config.debug = msg => {
Enabling debugging can generate a lot of output. If you use console.error() as the output (as in the example above), you can redirect the output to a file using shell redirection e.g.
```shell
+
+node
+
node script.js 2> debug.log
```
If you just want to see debug messages from `ssh2-sftp-client` and exclude debug messages from the underlying `ssh2` and `ssh2-streams` modules, you can filter based on messages which start with 'CLIENT' e.g.
-```javascript
-{
- debug: (msg) => {
- if (msg.startsWith('CLIENT')) {
- console.error(msg);
- }
- }
-}
+```nillangnilswitchesnilflags
+nilbody
+#+END_SRC
+*
+nilbody
```
-
-
-
-# Logging Issues
+# Logging Issues
Please log an issue for all bugs, questions, feature and enhancement requests. Please ensure you include the module version, node version and platform.
@@ -1552,10 +1487,7 @@ I am happy to try and help diagnose and fix any issues you encounter while using
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.
-
-
-
-# Pull Requests
+# Pull Requests
Pull requests are always welcomed. However, please ensure your changes pass all tests and if you're adding a new feature, that tests for that feature are included. Likewise, for new features or enhancements, please include any relevant documentation updates.
@@ -1567,10 +1499,7 @@ This module will adopt a standard semantic versioning policy. Please indicate in
- **Minor:** Minor change, enhancement or new feature which does not change existing API and will not break existing client code.
- **Bug Fix:** No change to functionality or features. Simple fix of an existing bug.
-
-
-
-# Contributors
+# Contributors
This module was initially written by jyu213. On August 23rd, 2019, theophilusx took over responsibility for maintaining this module. A number of other people have contributed to this module, but until now, this was not tracked. My intention is to credit anyone who contributes going forward.
@@ -1589,4 +1518,4 @@ Thanks to the following for their contributions -
- **Emma Milner:** Contributed fix for put() bug
- **Witni Davis:** Contributed PR to fix put() RCE when using 'finish' rather than 'close' to resolve promise
- **Maik Marschner:** Contributed fix for connect() not returning sftp object. Also included test to check for this regression in future.
-- **cakemasher:** Contributed fix for removeTempListeners().
\ No newline at end of file
+- **cakemasher:** Contributed fix for removeTempListeners().
diff --git a/README.org b/README.org
index 01b9d37..9f4d3a0 100644
--- a/README.org
+++ b/README.org
@@ -30,11 +30,11 @@ Node versions < 14.x are not supported.
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
+ value. Both these handlers will now invalidate the SFTP connection object and log that
the event fired and nothing else.
- Changed when event handled flags are reset. Now they are reset after a new set of
temporary listeners are added.
- - Don't throw an error when calling end() if there is no active sftp connection. It does
+ - 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.
- Use nullish coalescing when setting retry parameters instead of or'ing with
defaults. Allows setting values to 0.
@@ -60,20 +60,20 @@ Node versions < 14.x are not supported.
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
+ the ~fastPut()~ method will be used 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
+ downloading files, otherwise the slower, but more reliable, ~get()~ method
will be used.
- - The ~uploadDir()~ and ~downloadDir()~ methods now use asynchrounous processes to
+ - The ~uploadDir()~ and ~downloadDir()~ methods now use asynchronous processes to
upload/download files. This should result in improved performance for these
two methods.
- New Methods: Two new methods, ~createWriteStream()~ and ~createReadStream()~
have been added. These methods will return a stream object connected to a
- remote file on the ~sftp~ server. Client code is responsible for managing
+ remote file on the ~SFTP~ server. Client code is responsible for managing
these stream objects. This includes adding any necessary event listeners and
disposing of the objects once finished with them.
- - Refactoring of Listeners: The library manages temporary listeners in order
+ - Re-factoring of Listeners: The library manages temporary listeners in order
to provide a way to catch events and processes them inside a ~Promise~
context. Previously, every method added its own set of temporary listeners.
However, this could result in multiple sets of listeners being added,
@@ -87,7 +87,7 @@ Node versions < 14.x are not supported.
* Installation
#+begin_src shell
-npm install ssh2-sftp-client
+ npm install ssh2-sftp-client
#+end_src
* Basic Usage
@@ -154,7 +154,7 @@ All the methods will return a Promise, except for ~on()~ and
more robust.
When specifying file paths, ensure to include a full path i.e. include the
- remote filename. Don't expect the module to append the local file name to the
+ remote file name. Don't expect the module to append the local file name to the
path you provide. For example, the following will not work
#+begin_src javascript
@@ -162,7 +162,7 @@ All the methods will return a Promise, except for ~on()~ and
#+end_src
will not result in the file ~test.txt~ being copied to
- ~/remote/dir/test.txt~. You need to specify the target filename as well e.g.
+ ~/remote/dir/test.txt~. You need to specify the target file name as well e.g.
#+begin_src javascript
client.put('/home/fred/test.txt', '/remote/dir/test.txt');
@@ -827,11 +827,11 @@ necessary permissions to modify the remote file.
This method uses the openssh POSIX rename extension introduced in OpenSSH 4.8.
The advantage of this version of rename over standard SFTP rename is that it is
an atomic operation and will allow renaming a resource where the destination
-name exists. The POSIX rename will also work on some filesystems which do not
+name exists. The POSIX rename will also work on some file systems which do not
support standard SFTP rename because they don't support the system hardlink()
call. The POSIX rename extension is available on all openSSH servers from 4.8
and some other implementations. This is an extension to the standard SFTP
-protocol and therefore is not supported on all sSFTP servers.
+protocol and therefore is not supported on all sftp servers.
- fromPath :: string. Path to existing file to be renamed.
- toPath :: string. Path for new name. If it already exists, it will be replaced
@@ -1004,7 +1004,7 @@ required. All sub directories within ~srcDir~ will also be copied. Any existing
files in the local path will be overwritten. No files in the local path will be
deleted.
-The method also emites ~download~ events to provide a way to monitor download
+The method also emits ~download~ events to provide a way to monitor download
progress. The download event listener is called with one argument, an object
with two properties, source and destination. The source property is the path to
the remote file that has been downloaded and the destination is the local path
@@ -1033,7 +1033,7 @@ services.
function is called for each item in the download path and should return true
to include the item and false to exclude it in the download. The ~useFastget~
property is a boolean. If true, the ~fastGet()~ method will be used to transfer
- files. If ~false~ (the default), the slower but better supported ~get()~ mehtod is
+ files. If ~false~ (the default), the slower but better supported ~get()~ method is
used. .
**** Example
@@ -1101,19 +1101,19 @@ services.
- autoClose :: defaults to true. If set to false, client code is responsible
for closing file descriptors when finished
- start :: Default 0. Position to start reading bytes from (inclusive)
- - end :: Postion to stop reading bytes (inclusive).
+ - end :: Position to stop reading bytes (inclusive).
*** createWriteStream(remotePath, options) ==> stream object
Returns a write stream object which is attached to the remote file specified
- in the ~remotePath~ argument. This is a low legvel function which just returns
+ in the ~remotePath~ argument. This is a low level function which just returns
the stream object. Client code is fully responsible for managing that object,
- including closing any file descriptiors and removing listeners etc.
+ including closing any file descriptors and removing listeners etc.
- remotePath :: Path to the remote file specified as a string
- options :: An object containing stream options. Supported properties include
- flags :: default 'w'
- - encoding :: defulat null
+ - encoding :: default null
- mode :: 0o666
- autoClose :: true
- start :: Byte position to start writing from (inclusive). May require
@@ -1121,13 +1121,13 @@ services.
*** rcopy(srcPath, dstPath) ==> string
- Perfrom a remote file copy. The file identified by the ~srcPath~ argument will
+ Perform a remote file copy. The file identified by the ~srcPath~ argument will
be copied to the file specified as the ~dstPath~ argument. The directory where
~dstPath~ will be placed must exist, but the actual file must not i.e. no
overwrites allowed.
- srcPath :: Path to remote file to be copied specified as a string
- - dstPath :: Path to where the copy will be creaeted specified as a string
+ - dstPath :: Path to where the copy will be created specified as a string
*** end() ==> boolean
@@ -1181,7 +1181,7 @@ the ~end()~ method automatically removes all listeners from the client object.
All SFTP servers and platforms are not equal. Some facilities provided by
~ssh2-sftp-client~ either depend on capabilities of the remote server or the
underlying capabilities of the remote server platform. As an example,
- consider ~chmod()~. This command depends on a remote filesystem which
+ consider ~chmod()~. This command depends on a remote file system which
implements the 'nix' concept of users and groups. The /win32/ platform does
not have the same concept of users and groups, so ~chmod()~ will not behave
in the same way.
@@ -1203,7 +1203,7 @@ the ~end()~ method automatically removes all listeners from the client object.
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.
+ a specific packet size.
To see an example of the type of issues you can observe with ~fastPut()~ or
~fastGet()~, have a look at [[https://github.com/theophilusx/ssh2-sftp-client/issues/407][issue 407]], which describes the experiences of one
@@ -1229,7 +1229,7 @@ the ~end()~ method automatically removes all listeners from the client object.
=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
+ example 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.
@@ -1251,7 +1251,7 @@ the ~end()~ method automatically removes all listeners from the client object.
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
+ and =close= event listeners which will call the =reject= method 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
@@ -1268,7 +1268,7 @@ the ~end()~ method automatically removes all listeners from the client object.
until all events have been caught.
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
+ deal with these events, the =end()= method sets 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
@@ -1353,7 +1353,7 @@ 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.
-** How can I pass writable stream as dst for get method?
+** How can I pass writeable stream as dst for get method?
If the dst argument passed to the get method is a writeable stream, the remote
file will be piped into that writeable. If the writeable you pass in is a
@@ -1498,7 +1498,7 @@ documentation for details. Getting these parameters correct usually resolves the
issue.
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
+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.
@@ -1606,7 +1606,7 @@ the ~ssh2-sftp-client~ wrapper module.
** Common Errors
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
+ 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.
@@ -1746,7 +1746,7 @@ the ~ssh2-sftp-client~ wrapper module.
The basic problem is that the try/catch block will have completed execution
before the asynchronous code has completed. If the asynchronous code has not
- compleed, then there is a potential for it to raise an error. However, as
+ completed, then there is a potential for it to raise an error. However, as
the try/catch block has already completed, there is no /catch/ waiting to
catch the error. It will bubble up and probably result in your script
exiting with an uncaught exception error.