|
| 1 | +import org.apache.ftpserver.FtpServer; |
| 2 | +import org.apache.ftpserver.FtpServerFactory; |
| 3 | +import org.apache.ftpserver.ftplet.FtpException; |
| 4 | +import org.apache.ftpserver.listener.ListenerFactory; |
| 5 | +import org.apache.ftpserver.ssl.SslConfigurationFactory; |
| 6 | +import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory; |
| 7 | + |
| 8 | +import java.io.File; |
| 9 | + |
1 | 10 | public class Playground { |
2 | | - public static void main(String[] args) { |
| 11 | + public static void main(String[] args) throws FtpException { |
| 12 | + FtpServerFactory serverFactory = new FtpServerFactory(); |
| 13 | + |
| 14 | + ListenerFactory factory = new ListenerFactory(); |
| 15 | + |
| 16 | + // set the port of the listener |
| 17 | + factory.setPort(2221); |
| 18 | + |
| 19 | + // define SSL configuration |
| 20 | + SslConfigurationFactory ssl = new SslConfigurationFactory(); |
| 21 | + ssl.setKeystoreFile(new File("ftpserver.jks")); |
| 22 | + ssl.setKeystorePassword("password"); |
| 23 | + |
| 24 | + // set the SSL configuration for the listener |
| 25 | + factory.setSslConfiguration(ssl.createSslConfiguration()); |
| 26 | + factory.setImplicitSsl(true); |
| 27 | + |
| 28 | + // replace the default listener |
| 29 | + serverFactory.addListener("default", factory.createListener()); |
| 30 | + |
| 31 | + PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); |
| 32 | + userManagerFactory.setFile(new File("users.properties")); |
| 33 | + |
| 34 | + serverFactory.setUserManager(userManagerFactory.createUserManager()); |
3 | 35 |
|
| 36 | + // start the server |
| 37 | + FtpServer server = serverFactory.createServer(); |
| 38 | + //mFtpServer = server; |
| 39 | + try { |
| 40 | + server.start(); |
| 41 | + } catch (FtpException e) { |
| 42 | + e.printStackTrace(); |
| 43 | + } |
4 | 44 | } |
5 | 45 | } |
0 commit comments