basic-ftp
Advanced tools
Comparing version 2.13.1 to 2.13.2
# Changelog | ||
## 2.13.2 | ||
- Various improvements to documentation. | ||
## 2.13.1 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "basic-ftp", | ||
"version": "2.13.1", | ||
"version": "2.13.2", | ||
"description": "FTP client for Node.js with support for explicit FTPS over TLS.", | ||
@@ -30,5 +30,5 @@ "main": "./lib/ftp", | ||
"devDependencies": { | ||
"eslint": "4.19.1", | ||
"eslint": "5.0.1", | ||
"mocha": "5.2.0" | ||
} | ||
} |
@@ -7,2 +7,6 @@ # Basic FTP | ||
## Advisory | ||
Prefer alternative transfer protocols like SFTP if you can. Use this library when you have no choice and need to use FTP. Try to use FTPS whenever possible, FTP alone does not encrypt your data. | ||
## Dependencies | ||
@@ -67,33 +71,13 @@ | ||
Convenience method to get access to an FTP server. This method calls *connect*, *useTLS*, *login* and *useDefaultSettings* described below. It returns the response of the initial connect command. The available options are: | ||
Get access to an FTP server. This method will connect to a server, optionally secure the connection with TLS, login a user and apply some default settings (TYPE I, STRU F, PBSZ 0, PROT P). It returns the response of the initial connect command. The available options are: | ||
- `host (string)`: Host to connect to | ||
- `port (number)`: Port to connect to | ||
- `user (string)`: Username for login | ||
- `password (string)`: Password for login | ||
- `secure (boolean)`: Use explicit FTPS over TLS | ||
- `secureOptions`: Options for TLS, same as for [tls.connect()](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback) in Node.js. | ||
- `host (string)` Server host, default: localhost | ||
- `port (number)` Server port, default: 21 | ||
- `user (string)` Username, default: anonymous | ||
- `password (string)` Password, default: guest | ||
- `secure (boolean)` Explicit FTPS over TLS, default: false | ||
- `secureOptions` Options for TLS, same as for [tls.connect()](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback) in Node.js. | ||
--- | ||
The following setup methods are for advanced users who want to customize an aspect of accessing an FTP server. If you use *client.access* you won't need them. | ||
`connect(host = "localhost", port = 21): Promise<Response>` | ||
Connect to an FTP server. | ||
`useTLS([options]): Promise<Response>` | ||
Upgrade the existing control connection with TLS. You may provide options that are the same you'd use for [tls.connect()](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback) in Node. Remember to upgrade before you log in. Subsequently created data connections will automatically be upgraded to TLS reusing the session negotiated by the control connection. | ||
`login(user = "anonymous", password = "guest"): Promise<Response>` | ||
Login with a username and a password. | ||
`useDefaultSettings(): Promise<Response>` | ||
Sends FTP commands to use binary mode (TYPE I) and file structure (STRU F). If TLS is enabled it will also send PBSZ 0 and PROT P. It's recommended that you call this method after upgrading to TLS and logging in. | ||
--- | ||
`features(): Promise<Map<string, string>>` | ||
@@ -198,5 +182,5 @@ | ||
Errors reported by the FTP server will throw an exception. The connection to the FTP server stays intact and can still be used. | ||
Errors reported by the FTP server will throw an exception. The connection to the FTP server stays intact and you can continue to use it. | ||
A timeout, connection or any other error will throw an exception as well but also close any connection to the FTP server. You have to instantiate a new client and reconnect to resume any operation. | ||
This is different with a timeout or connection error: In addition to an exception being thrown, any connection to the FTP server will be closed. You have to instantiate a new client and reconnect to resume any operation. | ||
@@ -230,23 +214,19 @@ Here are examples for the 3 different types of error messages you'll receive: | ||
## Customize | ||
## Extending the library | ||
The `Client` offers extension points that allow you to change a detail while still using existing functionality like uploading a whole directory. | ||
### Custom strategies | ||
`get/set client.prepareTransfer` | ||
`get/set client.prepareTransfer` | ||
FTP creates a socket connection for each single data transfer. Data transfers include directory listings, file uploads and downloads. This property holds the function that prepares this connection. Currently, this library offers Passive Mode over IPv4 (PASV) and IPv6 (EPSV) but this extension point makes support for Active Mode possible. The signature of the function is `(ftp: FTPContext) => Promise<void>` and its job is to set `ftp.dataSocket`. The section below about extending functionality explains what `FTPContext` is. | ||
Provide a function that initializes a data connection. FTP uses a dedicated socket connection for each file upload, download and directory listing. This library supports two strategies: Passive Mode over IPv4 (PASV) and IPv6 (EPSV). Active Mode is not supported but could be added using this extension point. The signature of the function is `(client: Client) => Promise<void>` and its job is to set `client.ftp.dataSocket`. | ||
`get/set client.parseList` | ||
You can provide a custom parser to parse directory listing data. This library supports Unix and DOS formats out-of-the-box. Parsing these list responses is one of the more challenging parts of FTP because there is no standard that all servers adhere to. The signature of the function is `(rawList: string) => FileInfo[]`. `FileInfo` is also exported by the library. | ||
Provide a function to parse directory listing data. This library supports Unix and DOS formats. Parsing these list responses is one of the more challenging parts of FTP because there is no standard that all servers adhere to. The signature of the function is `(rawList: string) => FileInfo[]`. | ||
## Extend | ||
### FTPContext | ||
You can use `client.send` to send any FTP command and get its result. This might not be good enough, though. FTP can return multiple responses after a command and a simple command-response pattern won't work. You might also want to have access to sockets. | ||
The Client API described so far is implemented using an FTPContext. An FTPContext provides the foundation to write an FTP client. It holds the socket connections and provides an API to handle responses and events in a simplified way. Through `client.ftp` you get access to this context. | ||
The `Client` described above is just a collection of convenience functions using an underlying `FTPContext`. An FTPContext provides the foundation to write an FTP client. It holds the socket connections and provides an API to handle responses and events in a simplified way. Through `client.ftp` you get access to this context. | ||
### FTPContext API | ||
`get/set verbose` | ||
@@ -258,3 +238,3 @@ | ||
Get or set the encoding applied to all incoming and outgoing messages of the control connection. This encoding is also used when parsing a list response from a data connection. Node supports `utf8`, `latin1` and `ascii`. Default is `utf8` because it's backwards-compatible with `ascii` and many modern servers support it, some of them without mentioning it when requesting features. You can change this setting at any time. | ||
Set the encoding applied to all incoming and outgoing messages of the control connection. This encoding is also used when parsing a list response from a data connection. Node supports `utf8`, `latin1` and `ascii`. Default is `utf8` because it's backwards-compatible with `ascii` and many modern servers support it, some of them without mentioning it when requesting features. | ||
@@ -267,7 +247,7 @@ `get/set ipFamily` | ||
Get or set the socket for the control connection. When setting a new socket the current one will *not* be closed because you might be just upgrading the control socket. All listeners will be removed, though. | ||
Set the socket for the control connection. When setting a new socket the current one will *not* be closed because you might be just upgrading the control socket. All listeners will be removed, though. | ||
`get/set dataSocket` | ||
Get or set the socket for the data connection. When setting a new socket the current one will be closed and all listeners will be removed. | ||
Set the socket for the data connection. When setting a new socket the current one will be closed and all listeners will be removed. | ||
@@ -286,3 +266,3 @@ `handle(command, handler): Promise<Response>` | ||
### Example | ||
### Using FTPContext | ||
@@ -289,0 +269,0 @@ The best source of examples is the implementation of the `Client` itself as it's using the same single pattern you will use. The code below shows a simplified file upload. Let's assume a transfer connection has already been established. |
107194
285