【发布时间】:2026-01-23 04:45:01
【问题描述】:
我正在尝试使用 Apache FtpServer 在 Java 中设置一个简单的测试 FTPS 服务器,并使用域名而不是 IP 地址连接到它。
我已将 A 记录指向 IP 地址并设置了 SSL 证书。基于Apache FtpServer documentation,这是我的代码到目前为止的样子:
FtpServerFactory ftpServerFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(990);
listenerFactory.setServerAddress("example.com");
SslConfigurationFactory sslConfigurationFactory = new SslConfigurationFactory();
sslConfigurationFactory.setKeystoreFile(JKS);
sslConfigurationFactory.setKeystorePassword(JKS_PASS);
listenerFactory.setSslConfiguration(sslConfigurationFactory.createSslConfiguration());
listenerFactory.setImplicitSsl(true);
ftpServerFactory.addListener("default", listenerFactory.createListener());
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(USERS_PATH.toFile());
BaseUser test = new BaseUser();
sample1.setName("test");
sample1.setPassword("test");
sample1.setHomeDirectory(HOME.getAbsolutePath().toString());
test.setAuthorities(List.of(new WritePermission());
UserManager userManager = userManagerFactory.createUserManager();
try {
userManager.save(test);
}
catch (FtpException e) {
e.printStackTrace();
}
ftpServerFactory.setUserManager(userManager);
FtpServer server = ftpServerFactory.createServer();
try {
server.start();
}
catch (FtpException e) {
e.printStackTrace();
}
但是,当我尝试连接到 FTPS 服务器时,我从我的 FTPS 客户端收到一个ECONNREFUSED - Connection refused by server。
有没有我遗漏的步骤?
【问题讨论】:
标签: java dns network-programming apache-mina apache-ftpserver