basic-ftp
Advanced tools
Comparing version 2.8.0 to 2.8.1
# Changelog | ||
## 2.8.1 | ||
- Improve documentation. | ||
- Update linter. | ||
## 2.8.0 | ||
@@ -4,0 +9,0 @@ |
@@ -5,6 +5,4 @@ # Contributing | ||
Please keep in mind that this project has clearly defined [goals and non-goals](README.md). There are many features one could add to an FTP library. The main feature of this one is being easy to compose and extend while the API should stay small. | ||
Please keep in mind that this project has specific [goals and non-goals](README.md). There are many features one could add to an FTP library. The main feature of this one is being easy to compose and extend while the API should stay small. | ||
That being said, what do I know. Maybe you'll take the library to a far more interesting place. In any case, open an issue before devoting too much time preparing a pull request and let's have a chat. | ||
## Testing | ||
@@ -11,0 +9,0 @@ |
@@ -16,6 +16,7 @@ "use strict"; | ||
/** | ||
* An FTPContext provides the foundation to write an FTP client. It holds the socket | ||
* connections and provides a pattern to handle responses and simplifies event handling. | ||
* FTPContext holds the state of an FTP client – its control and data connections – and provides a | ||
* simplified way to interact with an FTP server, handle responses, errors and timeouts. | ||
* | ||
* Users don't normally instantiate this, instead use an API like `Client`. | ||
* It doesn't implement or use any FTP commands. It's only a foundation to make writing an FTP | ||
* client as easy as possible. You won't usually instantiate this, but use `Client` below. | ||
*/ | ||
@@ -611,9 +612,7 @@ class FTPContext { | ||
FileInfo, | ||
// Useful for custom extensions and unit tests. | ||
// Useful for custom extensions. | ||
utils: { | ||
download, | ||
upload, | ||
list, | ||
upgradeSocket, | ||
parseControlResponse, | ||
parseIPv4PasvResponse, | ||
TransferResolver | ||
@@ -702,2 +701,3 @@ } | ||
const tlsSocket = tls.connect(tlsOptions, () => { | ||
// Make sure the certificate is valid if an unauthorized one should be rejected. | ||
const expectCertificate = tlsOptions.rejectUnauthorized !== false; | ||
@@ -739,3 +739,9 @@ if (expectCertificate && !tlsSocket.authorized) { | ||
socket = tls.connect(Object.assign({}, ftp.tlsOptions, { | ||
// Upgrade the existing socket connection. | ||
socket, | ||
// Reuse the TLS session negotiated earlier when the control connection | ||
// was upgraded. Servers expect this because it provides additional | ||
// security. If a completely new session would be negotiated, a hacker | ||
// could guess the port and connect to the new data connection before we do | ||
// by just starting his/her own TLS session. | ||
session: ftp.socket.getSession() | ||
@@ -742,0 +748,0 @@ })); |
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2017 Patrick Juchli | ||
Copyright (c) 2018 Patrick Juchli | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "basic-ftp", | ||
"version": "2.8.0", | ||
"description": "FTP/FTPS client library", | ||
"version": "2.8.1", | ||
"description": "FTP client for Node.js with support for explicit FTPS over TLS.", | ||
"main": "./lib/ftp", | ||
@@ -25,5 +25,5 @@ "scripts": { | ||
"devDependencies": { | ||
"eslint": "^4.16.0", | ||
"eslint": "^4.17.0", | ||
"mocha": "^5.0.0" | ||
} | ||
} |
@@ -5,9 +5,9 @@ # Basic FTP | ||
This is an FTP/FTPS client for NodeJS. | ||
This is an FTP client for Node.js, it supports explicit FTPS over TLS. | ||
## Goals and non-goals | ||
## Goals | ||
This library has two goals: Provide a solid foundation that covers the usual needs and make it easy for the user to extend functionality if necessary. | ||
Provide a foundation that covers the usual needs and make it possible to extend functionality. | ||
FTP is an old protocol, there are many features, quirks and server implementations. It's not a goal to support all of them. Instead, it should be possible for you to solve your specific issues without requiring a change in the library. | ||
FTP is an old protocol, there are many features, quirks and server implementations. It's not a goal to support all of them. Instead, make it possible to extend behaviour without requiring a change in the library itself. | ||
@@ -20,3 +20,3 @@ ## Dependencies | ||
`Client` provides a convenience API to interact with an FTP server. The following example shows how to connect, upgrade to TLS, login, get a directory listing and upload a file. | ||
`Client` provides an API to interact with an FTP server. The following example shows how to connect, upgrade to TLS, login, get a directory listing and upload a file. | ||
@@ -46,5 +46,5 @@ ```js | ||
The example sets the client to be `verbose`. This will log out all communication, making it easier to spot an issue and address it. It's also a great way to learn about FTP. Why the setting is behind a property `.ftp` will be answered in the section about extending the library. | ||
The example sets the client to be `verbose`. This will log out all communication, making it easier to spot an issue and address it. Why the setting is behind a property `.ftp` will be explained in a later section. | ||
Here is another example showing how to remove all files and directories recursively. It also shows that not all FTP commands are backed by a method. | ||
Here is another example that removes all files and directories recursively. It shows that not all FTP commands are backed by a method. Also, be aware that the FTP protocol doesn't allow parallel requests. | ||
@@ -67,2 +67,3 @@ ```js | ||
## Client API | ||
@@ -72,7 +73,7 @@ | ||
Create a client instance using an optional timeout in milliseconds that will be used for control and data connections. | ||
Create a client instance using an optional timeout in milliseconds that will be used for control and data connections. Use 0 to disable timeouts. | ||
`close()` | ||
Close all socket connections. The client can't be used anymore after calling this method. | ||
Close all socket connections. | ||
@@ -85,3 +86,3 @@ `connect(host, port = 21): 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 NodeJS. 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. | ||
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. | ||
@@ -94,3 +95,3 @@ `login(user = "anonymous", password = "guest"): 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. | ||
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. | ||
@@ -186,10 +187,13 @@ `features(): Promise<Map<string, string>>` | ||
`Client` offers a number of extension points that allow you to change a detail and continue to use existing functionality like uploading a whole directory. | ||
`get/set client.prepareTransfer` | ||
You can provide a custom function that prepares the data connection for a transfer. FTP uses a dedicated 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. Right now the library only offers Passive Mode over IPv4. 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. | ||
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 only offers Passive Mode over IPv4, but this extension point makes support for Active Mode or IPv6 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. | ||
`get/set client.parseList` | ||
You can provide a custom parser to parse directory listing data. This library only supports Unix and DOS formats out-of-the-box. Parsing these list responses is a central part of every FTP client 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. | ||
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. | ||
## Extend | ||
@@ -217,3 +221,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. Possible values are `utf8`, `latin1`, `ascii`. Default is `utf8` because most modern servers support this and some of them don't even list this feature in the response of the FEAT command. You can change this setting at any time. | ||
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. | ||
@@ -220,0 +224,0 @@ `handle(command, handler): Promise<Response>` |
Sorry, the diff of this file is not supported yet
94792
1395
252