The binding has the following configuration options:
-| Parameter | Name | Description | Required | Default value |
-|-------------|--------------|------------------------------------------------------------------------------------------------------------------------|----------|---------------|
-| port | TCP Port | TCP port of the FTP server | no | 2121 |
-| idleTimeout | Idle timeout | The number of seconds before an inactive client is disconnected. If this value is set to 0, the idle time is disabled. | no | 60 |
+| Parameter | Name | Description | Required | Default value |
+|--------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------------|
+| port | TCP Port | TCP port of the FTP server | no | 2121 |
+| idleTimeout | Idle timeout | The number of seconds before an inactive client is disconnected. If this value is set to 0, the idle time is disabled. | no | 60 |
+| passivePorts | Passive Ports | A string of passive ports, can contain a single port (as an integer), multiple ports seperated by commas (e.g. 123,124,125) or ranges of ports, including open ended ranges (e.g. 123-125, 30000-, -1023). Combinations for single ports and ranges is also supported. Empty (default) allows all ports as passive ports. | no | |
## Thing Configuration
import java.util.Set;
import org.apache.commons.lang.StringUtils;
+import org.apache.ftpserver.DataConnectionConfigurationFactory;
import org.apache.ftpserver.FtpServerConfigurationException;
import org.apache.ftpserver.ftplet.FtpException;
import org.openhab.binding.ftpupload.internal.ftp.FtpServer;
protected synchronized void modified(ComponentContext componentContext) {
stopFtpServer();
Dictionary<String, Object> properties = componentContext.getProperties();
+ DataConnectionConfigurationFactory dataConnectionConfigurationFactory = new DataConnectionConfigurationFactory();
int port = DEFAULT_PORT;
int idleTimeout = DEFAULT_IDLE_TIMEOUT;
}
}
+ if (properties.get("passivePorts") != null) {
+ String strPassivePorts = properties.get("passivePorts").toString();
+ if (!strPassivePorts.isEmpty()) {
+ try {
+ dataConnectionConfigurationFactory.setPassivePorts(strPassivePorts);
+ } catch (IllegalArgumentException e) {
+ logger.warn("Invalid passive ports '{}' ({})", strPassivePorts, e.getMessage());
+ }
+ }
+ }
+
try {
logger.debug("Starting FTP server, port={}, idleTimeout={}", port, idleTimeout);
- ftpServer.startServer(port, idleTimeout);
+ ftpServer.startServer(port, idleTimeout,
+ dataConnectionConfigurationFactory.createDataConnectionConfiguration());
} catch (FtpException | FtpServerConfigurationException e) {
logger.warn("FTP server starting failed, reason: {}", e.getMessage());
}
import java.util.List;
import java.util.Map;
+import org.apache.ftpserver.DataConnectionConfiguration;
import org.apache.ftpserver.FtpServerConfigurationException;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.DefaultFtplet;
private final Logger logger = LoggerFactory.getLogger(FtpServer.class);
private int port;
+ private DataConnectionConfiguration dataConnectionConfiguration;
int idleTimeout;
private org.apache.ftpserver.FtpServer server;
FTPUserManager = new FTPUserManager();
}
- public void startServer(int port, int idleTimeout) throws FtpException {
+ public void startServer(int port, int idleTimeout, DataConnectionConfiguration dataConnectionConfiguration)
+ throws FtpException {
stopServer();
this.port = port;
this.idleTimeout = idleTimeout;
+ this.dataConnectionConfiguration = dataConnectionConfiguration;
FTPUserManager.setIdleTimeout(idleTimeout);
initServer();
}
private void initServer() throws FtpException {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
+
listenerFactory.setPort(port);
listenerFactory.setIdleTimeout(idleTimeout);
+ listenerFactory.setDataConnectionConfiguration(dataConnectionConfiguration);
Listener listener = listenerFactory.createListener();
time is disabled.</description>
<default>60</default>
</parameter>
+ <parameter name="passivePorts" type="text">
+ <label>Passive Port Range</label>
+ <description>A string of passive ports, can contain a single port (as an integer), multiple ports seperated by
+ commas
+ (e.g. 123,124,125) or ranges of ports, including open ended ranges (e.g. 123-125, 30000-, -1023).
+ Combinations for
+ single ports and ranges is also supported. Empty (default) allows all ports as passive ports.</description>
+ <default></default>
+ <advanced>true</advanced>
+ </parameter>
</config-description>
</binding:binding>