2

I made simple Apache MINA FTP server in Spring boot. Similar to project mina-ftp-server in this github repo. Main configuration looks like this:

@Configuration
class FtpServerConfiguration {

    @Bean
    FileSystemFactory fileSystemFactory() {
        NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
        fileSystemFactory.setCreateHome(true);
        fileSystemFactory.setCaseInsensitive(false);
        return fileSystemFactory::createFileSystemView;
    }

    @Bean
    Listener nioListener(@Value("${ftp.port:7777}") int port) {
        ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort(port);
        return listenerFactory.createListener();
    }

    @Bean
    FtpServer ftpServer(Map<String, Ftplet> ftpletMap, UserManager userManager, Listener nioListener, FileSystemFactory fileSystemFactory) {
        FtpServerFactory ftpServerFactory = new FtpServerFactory();
        ftpServerFactory.setListeners(Collections.singletonMap("default", nioListener));
        ftpServerFactory.setFileSystem(fileSystemFactory);
        ftpServerFactory.setFtplets(ftpletMap);
        ftpServerFactory.setUserManager(userManager);
        return ftpServerFactory.createServer();
    }

    @Bean
    DisposableBean destroysFtpServer(FtpServer ftpServer) {
        return ftpServer::stop;
    }

    @Bean
    InitializingBean startsFtpServer(FtpServer ftpServer) {
        return ftpServer::start;
    }

    @Bean
    UserManager userManager(@Value("${ftp.root:${HOME}/Desktop/root}") File root, JdbcTemplate template) {
        Assert.isTrue(root.exists() || root.mkdirs(), "the root directory must exist.");
        return new FtpUserManager(root, template);
    }

}

The problem is that FTP server should have updated directory tree whenever server is restarted. So new folder(s) should be added depending on some other variable.

Is there a way to "seed" initial directory tree when starting Apache MINA FTP server? Maybe injecting admin FTPSession object right after start into some filter that I don't know about?

Galoman
  • 73
  • 6

0 Answers0