use of org.apache.ftpserver.FtpServerFactory in project AnExplorer by 1hakr.
the class ConnectionsService method launchServer.
@Override
public boolean launchServer() {
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(ConnectionUtils.getAvailablePortForFTP());
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.addListener("default", listenerFactory.createListener());
ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
connectionConfigFactory.setAnonymousLoginEnabled(getNetworkConnection().isAnonymousLogin());
connectionConfigFactory.setMaxLoginFailures(5);
connectionConfigFactory.setLoginFailureDelay(2000);
serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig());
BaseUser user = new BaseUser();
user.setName(getNetworkConnection().getUserName());
user.setPassword(getNetworkConnection().getPassword());
user.setHomeDirectory(getNetworkConnection().getPath());
List<Authority> list = new ArrayList<>();
list.add(new WritePermission());
list.add(new TransferRatePermission(0, 0));
list.add(new ConcurrentLoginPermission(10, 10));
user.setAuthorities(list);
try {
serverFactory.getUserManager().save(user);
} catch (FtpException e) {
CrashReportingManager.logException(e);
}
// do start server
try {
ftpServer = serverFactory.createServer();
ftpServer.start();
return true;
} catch (Exception e) {
ftpServer = null;
handleServerStartError(e);
}
return false;
}
use of org.apache.ftpserver.FtpServerFactory in project TeachingInSimulation by ScOrPiOzzy.
the class ServerConfig method createFtpServer.
@Bean
public FtpServer createFtpServer() {
// Apache Ftp Server 默认的编码是"UTF-8"
FtpServerFactory serverFactory = new FtpServerFactory();
// FTP服务连接配置
ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
// 允许匿名连接
connectionConfigFactory.setAnonymousLoginEnabled(true);
serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig());
//
serverFactory.setUserManager(userManager);
// 配置FTP端口
ListenerFactory listenerFactory = new ListenerFactory();
// 默认21, 可以按需配置
listenerFactory.setPort(ftpPort);
serverFactory.addListener("default", listenerFactory.createListener());
return serverFactory.createServer();
}
Aggregations