Skip to content

Commit

Permalink
feat: allow connecting from local
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Aug 22, 2019
1 parent 5ffcef3 commit 484409d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/commands/registration/pasv.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const PassiveConnector = require('../../connector/passive');
const {isLocalIP} = require('../../helpers/is-local');

module.exports = {
directive: 'PASV',
Expand All @@ -10,7 +11,11 @@ module.exports = {
this.connector = new PassiveConnector(this);
return this.connector.setupServer()
.then((server) => {
const address = this.server.options.pasv_url;
let address = this.server.options.pasv_url;
// Allow connecting from local
if (isLocalIP(this.ip)) {
address = this.ip;
}
const {port} = server.address();
const host = address.replace(/\./g, ',');
const portByte1 = port / 256 | 0;
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/is-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.isLocalIP = function(ip) {
return ip === '127.0.0.1' || ip == '::1';
}
2 changes: 1 addition & 1 deletion test/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const FtpServer = require('../src');
const server = new FtpServer({
log: bunyan.createLogger({name: 'test', level: 'trace'}),
url: 'ftp://127.0.0.1:8880',
pasv_url: '127.0.0.1',
pasv_url: '192.168.1.1',
pasv_min: 8881,
greeting: ['Welcome', 'to', 'the', 'jungle!'],
tls: {
Expand Down

0 comments on commit 484409d

Please sign in to comment.