[code="java"]public class FtpServerTest {
public static void main(String[] args) {
try {
FtpServerFactory serverFactory= new FtpServerFactory();
ListenerFactory factory=new ListenerFactory();
factory.setPort(21);
SslConfigurationFactory ssl = new SslConfigurationFactory();
File keystoreFile=new File("D:\up\ftpserver.jks");
ssl.setKeystoreFile(keystoreFile);
ssl.setKeyPassword("password");
SslConfiguration sc=ssl.createSslConfiguration();
factory.setSslConfiguration(sc);
factory.setServerAddress("127.0.0.1");
factory.setImplicitSsl(true);
serverFactory.addListener("default", factory.createListener());
//serverFactory.setUserManager(ftpService.userManager());
FtpServer server = serverFactory.createServer();
server.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
启动时一直报错
log4j:WARN No appenders could be found for logger (org.apache.ftpserver.ssl.SslConfigurationFactory).
log4j:WARN Please initialize the log4j system properly.
org.apache.ftpserver.FtpServerConfigurationException: DefaultSsl.configure()
at org.apache.ftpserver.ssl.SslConfigurationFactory.createSslConfiguration(SslConfigurationFactory.java:364)
at FtpServerTest.main(FtpServerTest.java:22)
Caused by: java.lang.NullPointerException
at org.apache.ftpserver.ssl.SslConfigurationFactory.loadStore(SslConfigurationFactory.java:305)
at org.apache.ftpserver.ssl.SslConfigurationFactory.createSslConfiguration(SslConfigurationFactory.java:326)
... 1 more
[/code]