diff --git a/README.md b/README.md index 33279a3..279321c 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,25 @@ A [bunyan logger](https://github.com/trentm/node-bunyan) instance. Created by de Sets the timeout (in ms) after that an idle connection is closed by the server __Default:__ `0` +## Renew TLS options +[`renewTlsOptions(tlsOptions)`](src/index.js#L172) is used to read and use a new set of TLS certificates without restarting the server. +Receives the same options as the [tls parameter](#tls) parameter in the constructor. +```js +let originalOptions = {}; +originalOptions.tls = { + key: fs.readFileSync("\path\to\old\key.pem"), + cert: fs.readFileSync("\path\to\old\cert.pem") +} +let ftpServer = new FtpServer(originalOptions); + +// Afterwards when the certificate is going to expire, it will need to be renewed +let newTlsOptions = { + key: fs.readFileSync("\path\to\new\key.pem"), + cert: fs.readFileSync("\path\to\new\cert.pem") +} +ftpServer.renewTlsOptions(newTlsOptions); +``` + ## CLI `ftp-srv` also comes with a builtin CLI. diff --git a/src/index.js b/src/index.js index 859540d..27d3a07 100644 --- a/src/index.js +++ b/src/index.js @@ -169,5 +169,9 @@ class FtpServer extends EventEmitter { }); } + renewTlsOptions(tlsOptions) { + this.server.setSecureContext(tlsOptions); + this.log.debug('Updating TLS options'); + } } module.exports = FtpServer;