Commit 6cca69ca authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '6-ftp-data-ports-range' into 'master'

(ftp) Data ports range

Closes #6

See merge request !8
parents a08aa147 7f007a76
......@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.ftpserver.ConnectionConfig;
import org.apache.ftpserver.DataConnectionConfigurationFactory;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.DefaultFtplet;
......@@ -30,6 +31,7 @@ import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.message.MessageResource;
import org.apache.ftpserver.ssl.SslConfigurationFactory;
import org.hsqldb.lib.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
......@@ -61,6 +63,10 @@ public class RepositoryFtpServer implements InitializingBean, DisposableBean {
private String keystorePsw;
private String passivePorts;
private String externalAddress;
private FtpServer server = null;
@Autowired
......@@ -72,7 +78,15 @@ public class RepositoryFtpServer implements InitializingBean, DisposableBean {
* <pre>keytool -genkey -alias testdomain -keyalg RSA -keystore ftpserver.jks -keysize 4096</pre>
* @param keystorePath
*/
public void setKeystorePath(final String keystorePath) {
public void setExternalAddress(final String externalAddress) {
this.externalAddress = externalAddress;
}
public void setPassivePorts(final String passivePorts) {
this.passivePorts = passivePorts;
}
public void setKeystorePath(final String keystorePath) {
this.keystorePath = keystorePath;
}
......@@ -129,6 +143,14 @@ public class RepositoryFtpServer implements InitializingBean, DisposableBean {
factory.setSslConfiguration(ssl.createSslConfiguration());
factory.setImplicitSsl(true);
// define Data Connection configuration
DataConnectionConfigurationFactory dccf = new DataConnectionConfigurationFactory();
dccf.setPassivePorts(passivePorts);
if (!StringUtil.isEmpty(externalAddress)) {
dccf.setPassiveExternalAddress(externalAddress);
}
factory.setDataConnectionConfiguration(dccf.createDataConnectionConfiguration());
// replace the default listener
serverFactory.addListener("default", factory.createListener());
}
......
......@@ -42,6 +42,11 @@ public class ApplicationConfig {
ftpServer.setUserManager(userManager());
ftpServer.setKeystorePath("ftpserver.jks");
ftpServer.setKeystorePsw("genesys");
//external IP address
// ftpServer.setExternalAddress("127.0.0.1");
ftpServer.setPassivePorts("2300-2301");
return ftpServer;
}
......
......@@ -171,6 +171,9 @@ public class FtpServerTest {
ftp.connect("localhost", 8021);
assertThat("FTP server refused connection", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
ftp.enterLocalPassiveMode();
assertThat(ftp.getDataConnectionMode(), is(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE));
ftp.login(username, password);
assertThat("Login failed", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
......@@ -207,6 +210,9 @@ public class FtpServerTest {
ftp.connect("localhost", 8021);
assertThat("FTP server refused connection", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
ftp.enterLocalPassiveMode();
assertThat(ftp.getDataConnectionMode(), is(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE));
ftp.login(username, password);
assertThat("Login failed", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
......@@ -229,6 +235,9 @@ public class FtpServerTest {
ftp.connect("localhost", 8021);
assertThat("FTP server refused connection", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
ftp.enterLocalPassiveMode();
assertThat(ftp.getDataConnectionMode(), is(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE));
ftp.login(username, password);
assertThat("Login failed", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
......@@ -276,6 +285,9 @@ public class FtpServerTest {
ftp.connect("localhost", 8021);
assertThat("FTP server refused connection", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
ftp.enterLocalPassiveMode();
assertThat(ftp.getDataConnectionMode(), is(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE));
ftp.login(username, password);
assertThat("Login failed", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
......@@ -323,6 +335,9 @@ public class FtpServerTest {
ftp.connect("localhost", 8021);
assertThat("FTP server refused connection", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
ftp.enterLocalPassiveMode();
assertThat(ftp.getDataConnectionMode(), is(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE));
ftp.login(username, password);
assertThat("Login failed", FTPReply.isPositiveCompletion(ftp.getReplyCode()), is(true));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment