Skip to content

Commit

Permalink
feat: pasv_url option to send to client
Browse files Browse the repository at this point in the history
This has passive connections to listen on the same hostname as the server.
But allows this to be customized via the `pasv_url` option.

Hostnames are no longer resolved if given `0.0.0.0`, except when being given to the client via `PASV`
  • Loading branch information
trs committed May 25, 2018
1 parent b0463d6 commit d9fc0c9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ Supported protocols:
- `ftp` Plain FTP
- `ftps` Implicit FTP over TLS

_Note:_ The hostname must be the external IP address to accept external connections. Setting the hostname to `0.0.0.0` will automatically set the external IP.
_Note:_ The hostname must be the external IP address to accept external connections. `0.0.0.0` will listen on any available hosts for server and passive connections.
__Default:__ `"ftp://127.0.0.1:21"`

#### options

##### `pasv_url`
The hostname to provide a client when attempting a passive connection (`PASV`). This defaults to the provided `url`.
_Note:_ If set to `0.0.0.0`, this will automatically resolve to the external IP of the box.
__Default:__ `"127.0.0.1"`

##### `pasv_range`
A starting port (eg `8000`) or a range (eg `"8000-9000"`) to accept passive connections.
This range is then queried for an available port to use when required.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/registration/pasv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
this.connector = new PassiveConnector(this);
return this.connector.setupServer()
.then(server => {
const address = this.server.url.hostname;
const address = this.server.options.pasv_url;
const {port} = server.address();
const host = address.replace(/\./g, ',');
const portByte1 = port / 256 | 0;
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FtpServer extends EventEmitter {
log: buyan.createLogger({name: 'ftp-srv'}),
anonymous: false,
pasv_range: 22,
pasv_url: null,
file_format: 'ls',
blacklist: [],
whitelist: [],
Expand Down Expand Up @@ -62,9 +63,10 @@ class FtpServer extends EventEmitter {
}

listen() {
return resolveHost(this.url.hostname)
.then(hostname => {
this.url.hostname = hostname;
return resolveHost(this.options.pasv_url || this.url.hostname)
.then(pasvUrl => {
this.options.pasv_url = pasvUrl;

return new Promise((resolve, reject) => {
this.server.once('error', reject);
this.server.listen(this.url.port, this.url.hostname, err => {
Expand Down
2 changes: 1 addition & 1 deletion test/connector/passive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Connector - Passive //', function () {
encoding: 'utf8',
log: bunyan.createLogger({name: 'passive-test'}),
commandSocket: {},
server: {options: {}}
server: {options: {}, url: {}}
};
let sandbox;

Expand Down

0 comments on commit d9fc0c9

Please sign in to comment.