Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Now, let's configure the port on which the default listener waits for connections.

Code Block
        FtpServerFactory serverFactory = new FtpServerFactory();
        
        ListenerFactory factory = new ListenerFactory();
        
        // set the port of the listener
        factory.setPort(2221);

        // replace the default listener
        serverFactory.addListener("default", factory.createListener());
                
        // start the server
        FtpServer server = serverFactory.createServer(); 
        
        server.start();

Now, let's make it possible for a client to use FTPS (FTP over SSL) for the default listener.

Code Block
        
FtpServerFactory serverFactory = new FtpServerFactory();
        
        ListenerFactory factory = new ListenerFactory();
        
        // set the port of the listener
        factory.setPort(2221);

        // define SSL configuration
        SslConfigurationFactory ssl = new SslConfigurationFactory();
        ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
        ssl.setKeystorePassword("password");

        // set the SSL configuration for the listener
        factory.setSslConfiguration(ssl.createSslConfiguration());
        factory.setImplicitSsl(true);

        // replace the default listener
        serverFactory.addListener("default", factory.createListener());
        
        PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
        userManagerFactory.setFile(new File("myusers.properties"));
        
        serverFactory.setUserManager(userManagerFactory.createUserManager());
        
        // start the server
        FtpServer server = serverFactory.createServer(); 
        
        server.start();

There you have it, that's the basics that you usually need. For more advanced features, have a look at our configuration documentation.