From 548af296e6545c60c8034e2ccbdee593ffacb7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Mu=CC=88ller?= Date: Tue, 18 Dec 2018 12:57:33 +0100 Subject: [PATCH] Allow to set the ports to use in FTP passive mode This is important as we need to limit the range of possible ports for dockerization. --- src/main/java/sirius/biz/vfs/ftp/FTPBridge.java | 14 ++++++++++++++ src/main/resources/component-biz.conf | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/sirius/biz/vfs/ftp/FTPBridge.java b/src/main/java/sirius/biz/vfs/ftp/FTPBridge.java index 73d9d6d7c..cda6918d9 100644 --- a/src/main/java/sirius/biz/vfs/ftp/FTPBridge.java +++ b/src/main/java/sirius/biz/vfs/ftp/FTPBridge.java @@ -8,6 +8,7 @@ package sirius.biz.vfs.ftp; +import org.apache.ftpserver.DataConnectionConfigurationFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.FtpException; @@ -38,6 +39,9 @@ public class FTPBridge { @ConfigValue("vfs.ftp.port") private int ftpPort; + @ConfigValue("vfs.ftp.passivePorts") + private String passivePorts; + @ConfigValue("vfs.ftp.bindAddress") private String bindAddress; @@ -122,9 +126,19 @@ private void createFTPServer() { private void setupNetwork(ListenerFactory factory) { factory.setPort(ftpPort); factory.setIdleTimeout((int) idleTimeout.getSeconds()); + if (Strings.isFilled(bindAddress)) { factory.setServerAddress(bindAddress); } + + if (Strings.isFilled(passivePorts)) { + DataConnectionConfigurationFactory dataConnectionConfigurationFactory = + new DataConnectionConfigurationFactory(); + + dataConnectionConfigurationFactory.setPassivePorts(passivePorts); + + factory.setDataConnectionConfiguration(dataConnectionConfigurationFactory.createDataConnectionConfiguration()); + } } private void setupFtplets(FtpServerFactory serverFactory) { diff --git a/src/main/resources/component-biz.conf b/src/main/resources/component-biz.conf index 8d45690a5..436e825cd 100644 --- a/src/main/resources/component-biz.conf +++ b/src/main/resources/component-biz.conf @@ -379,6 +379,14 @@ vfs { # Specifies the port to listen on. Use 0 to disable the server or 21 to run it on the common FTP port. port = 0 + # Specifies the port range to listen on for the data connection in passive mode, use any by default + # Examples: + # 2300 only use port 2300 as the passive port + # 2300-2399 use all ports in the range + # 2300- use all ports larger than 2300 + # 2300, 2305, 2400- use 2300 or 2305 or any port larger than 2400 + passivePorts = "" + # Specifies the IP address to bind to. Leave empty to use all IP addresses. bindAddress = ""