basic-ftp
Advanced tools
Comparing version 2.5.2 to 2.6.0
# Changelog | ||
## 2.6.0 | ||
- Add method to retrieve file size. | ||
## 2.5.2 | ||
@@ -4,0 +8,0 @@ |
@@ -281,4 +281,3 @@ "use strict"; | ||
} | ||
// We reject with all other codes, that includes the code 120, | ||
// standing for "Service ready in nnn minutes". | ||
// Reject all other codes, including 120 "Service ready in nnn minutes". | ||
else { | ||
@@ -314,19 +313,11 @@ task.reject(res); | ||
* @param {Object} [options] TLS options as in `tls.connect(options)` | ||
* @param {string} [command="AUTH TLS"] Set the auth command, e.g. "AUTH SSL". | ||
* @param {string} [command="AUTH TLS"] Set the authentication command, e.g. "AUTH SSL" instead of "AUTH TLS". | ||
* @return {Promise<PositiveResponse>} | ||
*/ | ||
useTLS(options, command = "AUTH TLS") { | ||
return this.ftp.handle(command, (res, task) => { | ||
if (positiveCompletion(res.code)) { | ||
upgradeSocket(this.ftp.socket, options).then(tlsSocket => { | ||
this.ftp.log("Control socket is using " + tlsSocket.getProtocol()); | ||
this.ftp.socket = tlsSocket; // TLS socket is the control socket from now on | ||
this.ftp.tlsOptions = options; // Keep the TLS options for later data connections that should use the same options. | ||
task.resolve(res); | ||
}).catch(err => task.reject(err)); | ||
} | ||
else { | ||
task.reject(res); | ||
} | ||
}); | ||
async useTLS(options, command = "AUTH TLS") { | ||
const ret = await this.send(command); | ||
this.ftp.socket = await upgradeSocket(this.ftp.socket, options); | ||
this.ftp.tlsOptions = options; // Keep the TLS options for later data connections that should use the same options. | ||
this.ftp.log("Control socket is using " + this.ftp.socket.getProtocol()); | ||
return ret; | ||
} | ||
@@ -356,3 +347,3 @@ | ||
/** | ||
* Set some default settings. | ||
* Set some default settings you should be setting. | ||
*/ | ||
@@ -401,3 +392,3 @@ async useDefaultSettings() { | ||
const res = await this.send("FEAT", true); | ||
let features = new Map(); | ||
const features = new Map(); | ||
// Not supporting any special features will be reported with a single line. | ||
@@ -417,2 +408,15 @@ if (res.code < 400 && isMultiline(res.message)) { | ||
/** | ||
* Get the size of a file. | ||
* | ||
* @param {string} filename | ||
* @returns {Promise<number>} | ||
*/ | ||
async size(filename) { | ||
const res = await this.send("SIZE " + filename); | ||
// The size is part of the response message, for example: "213 555555" | ||
const size = res.message.match(/^\d\d\d (\d+)/)[1]; | ||
return parseInt(size, 10); | ||
} | ||
/** | ||
* Upload data from a readable stream and store it as a file with | ||
@@ -650,7 +654,7 @@ * a given filename in the current working directory. | ||
return new Promise((resolve, reject) => { | ||
options = Object.assign({}, options, { | ||
const tlsOptions = Object.assign({}, options, { | ||
socket // Establish the secure connection using the existing socket connection. | ||
}); | ||
const tlsSocket = tls.connect(options, () => { | ||
const expectCertificate = options.rejectUnauthorized !== false; | ||
const tlsSocket = tls.connect(tlsOptions, () => { | ||
const expectCertificate = tlsOptions.rejectUnauthorized !== false; | ||
if (expectCertificate && !tlsSocket.authorized) { | ||
@@ -657,0 +661,0 @@ reject(tlsSocket.authorizationError); |
{ | ||
"name": "basic-ftp", | ||
"version": "2.5.2", | ||
"version": "2.6.0", | ||
"description": "FTP/FTPS client library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/ftp", |
@@ -11,3 +11,3 @@ # Basic FTP | ||
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 changing 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, it should be possible for you to solve your specific issues without requiring a change in the library. | ||
@@ -79,5 +79,5 @@ ## Dependencies | ||
`useTLS([options])` | ||
`useTLS(options = undefined)` | ||
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_createserver_options_secureconnectionlistener) in NodeJS. Remember to upgrade before you log in. Subsequently created data connections will automatically be upgraded to TLS. | ||
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. | ||
@@ -88,6 +88,10 @@ `login(user = "anonymous", password = "guest")` | ||
`useDefaultSettings(client)` | ||
`useDefaultSettings()` | ||
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. This should be called after upgrading to TLS and logging in. | ||
`features()` | ||
Get a description of supported features. This will return a Map where keys correspond to FTP commands and values contain further details. | ||
`send(command, ignoreErrorCodes = false)` | ||
@@ -97,2 +101,6 @@ | ||
`size(filename)` | ||
Get the size of a file in the working directory. | ||
`cd(remotePath)` | ||
@@ -106,6 +114,2 @@ | ||
`features()` | ||
Get a description of supported features. This will return a Map where keys correspond to FTP commands and values contain further details. | ||
`list()` | ||
@@ -112,0 +116,0 @@ |
90388
1337
213