Java Code Examples for org.apache.ftpserver.ConnectionConfigFactory

The following examples show how to use org.apache.ftpserver.ConnectionConfigFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: ProjectX   Author: AlexMofer   File: FtpServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param port      端口
 * @param adminName 管理员名称
 * @param listener  用户变更监听
 * @param users     用户
 * @return FTP服务器
 */
public static FtpServer createServer(int port, String adminName,
                                     FtpUserManager.OnUserChangedListener listener,
                                     FtpUser... users) {
    final FtpServerFactory factory = new FtpServerFactory();
    final ListenerFactory lf = new ListenerFactory();
    lf.setPort(port);
    lf.setDataConnectionConfiguration(
            new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
    factory.addListener("default", lf.createListener());
    final FtpUserManagerFactory umf = FtpUserManagerFactory.getInstance();
    umf.reset();
    if (adminName != null)
        umf.setAdminName(adminName);
    umf.setOnUserChangedListener(listener);
    umf.setUsers(users);
    final FtpUserManager um = umf.createUserManager();
    factory.setUserManager(um);
    factory.setFileSystem(new FtpFileSystemFactory());
    final ConnectionConfigFactory ccf = new ConnectionConfigFactory();
    ccf.setAnonymousLoginEnabled(um.isAnonymousLoginEnabled());
    factory.setConnectionConfig(ccf.createConnectionConfig());
    return new FtpServer(factory.createServer());
}
 
Example #2
Source Project: ProjectX   Author: AlexMofer   File: FtpServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param port      端口
 * @param adminName 管理员名称
 * @param listener  用户变更监听
 * @param users     用户
 * @return FTP服务器
 */
public static FtpServer createServer(int port, String adminName,
                                     FtpUserManager.OnUserChangedListener listener,
                                     Collection<? extends FtpUser> users) {
    final FtpServerFactory factory = new FtpServerFactory();
    final ListenerFactory lf = new ListenerFactory();
    lf.setPort(port);
    lf.setDataConnectionConfiguration(
            new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
    factory.addListener("default", lf.createListener());
    final FtpUserManagerFactory umf = FtpUserManagerFactory.getInstance();
    if (adminName != null)
        umf.setAdminName(adminName);
    umf.setOnUserChangedListener(listener);
    umf.setUsers(users);
    final FtpUserManager um = umf.createUserManager();
    factory.setUserManager(um);
    factory.setFileSystem(new FtpFileSystemFactory());
    final ConnectionConfigFactory ccf = new ConnectionConfigFactory();
    ccf.setAnonymousLoginEnabled(um.isAnonymousLoginEnabled());
    factory.setConnectionConfig(ccf.createConnectionConfig());
    return new FtpServer(factory.createServer());
}
 
Example #3
Source Project: ProjectX   Author: AlexMofer   File: FtpServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param port            端口
 * @param contentResolver ContentResolver
 * @param homeDirectory   根目录路径
 * @return FTP服务器
 */
@SuppressWarnings("WeakerAccess")
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static FtpServer createServer(int port, ContentResolver contentResolver,
                                     DocumentFile homeDirectory) {
    final FtpServerFactory factory = new FtpServerFactory();
    final ListenerFactory lf = new ListenerFactory();
    lf.setPort(port);
    lf.setDataConnectionConfiguration(
            new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
    factory.addListener("default", lf.createListener());
    final FtpUserManagerFactory umf = FtpUserManagerFactory.getInstance();
    umf.setAnonymousEnable(new UriFtpFileSystemViewAdapter(contentResolver, homeDirectory));
    factory.setUserManager(umf.createUserManager());
    factory.setFileSystem(new FtpFileSystemFactory());
    factory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
    return new FtpServer(factory.createServer());
}
 
Example #4
Source Project: portable-ftp-server   Author: dubasdey   File: FTPServer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Start.
 */
public boolean start(){

	stop();
	
	ConnectionConfigFactory configFactory = new ConnectionConfigFactory();
	configFactory.setAnonymousLoginEnabled(false);
	configFactory.setMaxAnonymousLogins(0);
	
	configFactory.setMaxLoginFailures(5);
	configFactory.setLoginFailureDelay(30);

	configFactory.setMaxThreads(10);
	configFactory.setMaxLogins(10);

	ListenerFactory factory = new ListenerFactory();	
	factory.setPort(port);
	factory.setIdleTimeout(60);

	FtpServerFactory serverFactory = new FtpServerFactory();
	serverFactory.addListener("default", factory.createListener());
	serverFactory.setUserManager(userManager);
	serverFactory.setConnectionConfig(configFactory.createConnectionConfig());

    server = serverFactory.createServer();
    
    try{
        server.start();
    } catch (FtpException ex){
    	System.err.println(ex.getMessage());
    	return false;
    }
    return true;
	
}
 
Example #5
Source Project: ProjectX   Author: AlexMofer   File: FtpServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param port          端口
 * @param homeDirectory 根目录路径
 * @return FTP服务器
 */
public static FtpServer createServer(int port, File homeDirectory) {
    final FtpServerFactory factory = new FtpServerFactory();
    final ListenerFactory lf = new ListenerFactory();
    lf.setPort(port);
    lf.setDataConnectionConfiguration(
            new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
    factory.addListener("default", lf.createListener());
    final FtpUserManagerFactory umf = FtpUserManagerFactory.getInstance();
    umf.setAnonymousEnable(new FileFtpFileSystemViewAdapter(homeDirectory));
    factory.setUserManager(umf.createUserManager());
    factory.setFileSystem(new FtpFileSystemFactory());
    factory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
    return new FtpServer(factory.createServer());
}
 
Example #6
Source Project: ProjectX   Author: AlexMofer   File: FtpServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param port          端口
 * @param homeDirectory 根目录路径
 * @return FTP服务器
 */
public static FtpServer createServer(int port, String homeDirectory) {
    final FtpServerFactory factory = new FtpServerFactory();
    final ListenerFactory lf = new ListenerFactory();
    lf.setPort(port);
    lf.setDataConnectionConfiguration(
            new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
    factory.addListener("default", lf.createListener());
    final FtpUserManagerFactory umf = FtpUserManagerFactory.getInstance();
    umf.setAnonymousEnable(new FileFtpFileSystemViewAdapter(homeDirectory));
    factory.setUserManager(umf.createUserManager());
    factory.setFileSystem(new FtpFileSystemFactory());
    factory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
    return new FtpServer(factory.createServer());
}
 
Example #7
Source Project: google-drive-ftp-adapter   Author: andresoviedo   File: GFtpServerFactory.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void init() {
    setFileSystem(new FtpFileSystemView(controller, model, illegalChars, null, cacheUpdater));
    ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
    connectionConfigFactory.setMaxThreads(10);
    connectionConfigFactory.setAnonymousLoginEnabled(Boolean.valueOf(this.configuration.
            getProperty("ftp.anonymous.enabled", "false")));
    setConnectionConfig(connectionConfigFactory.createConnectionConfig());
    setUserManager(new FtpUserManagerFactory(configuration).createUserManager());

    // MFMT for directories (default mina command doesn't support it)
    CommandFactoryFactory ccf = new CommandFactoryFactory();
    ccf.addCommand("MFMT", new FtpCommands.MFMT());
    setCommandFactory(ccf.createCommandFactory());

    // TODO: set ftplet to control all commands
    Map<String, Ftplet> ftplets = new HashMap<>();
    ftplets.put("default", new FtpletController());
    setFtplets(ftplets);

    // set the port of the listener
    int port = Integer.parseInt(configuration.getProperty("port", String.valueOf(1821)));
    String serverAddress = configuration.getProperty("server", "");
    LOG.info("FTP server configured at '" + serverAddress + ":" + port + "'");
    ListenerFactory listenerFactory = new ListenerFactory();
    listenerFactory.setPort(port);
    if (!serverAddress.isEmpty()) {
        listenerFactory.setServerAddress(serverAddress);
    }

    // replace the default listener
    addListener("default", listenerFactory.createListener());
}
 
Example #8
Source Project: camel-quarkus   Author: apache   File: FtpTestResource.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> start() {
    try {
        final int port = AvailablePortFinder.getNextAvailable();

        ftpRoot = Files.createTempDirectory("ftp-");
        usrFile = Files.createTempFile("ftp-", ".properties");

        NativeFileSystemFactory fsf = new NativeFileSystemFactory();
        fsf.setCreateHome(true);

        PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
        pumf.setAdminName("admin");
        pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
        pumf.setFile(usrFile.toFile());

        UserManager userMgr = pumf.createUserManager();

        BaseUser user = new BaseUser();
        user.setName("admin");
        user.setPassword("admin");
        user.setHomeDirectory(ftpRoot.toString());

        List<Authority> authorities = new ArrayList<>();
        WritePermission writePermission = new WritePermission();
        writePermission.authorize(new WriteRequest());
        authorities.add(writePermission);
        user.setAuthorities(authorities);
        userMgr.save(user);

        ListenerFactory factory = new ListenerFactory();
        factory.setPort(port);

        FtpServerFactory serverFactory = new FtpServerFactory();
        serverFactory.setUserManager(userMgr);
        serverFactory.setFileSystem(fsf);
        serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
        serverFactory.addListener("default", factory.createListener());

        FtpServerFactory ftpServerFactory = serverFactory;
        ftpServer = ftpServerFactory.createServer();
        ftpServer.start();

        return CollectionHelper.mapOf(
                "camel.ftp.test-port", Integer.toString(port),
                "camel.ftp.test-root-dir", ftpRoot.toString(),
                "camel.ftp.test-user-file", usrFile.toString());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
Source Project: o2oa   Author: o2oa   File: StorageServerTools.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
public static FtpServer start(StorageServer storageServer) throws Exception {
	/** 服务器工厂 */
	FtpServerFactory serverFactory = new FtpServerFactory();
	/*** 连接工厂 */
	ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
	connectionConfigFactory.setAnonymousLoginEnabled(false);
	connectionConfigFactory.setMaxLogins(1000);
	connectionConfigFactory.setMaxThreads(1000);
	/** 监听工厂 */
	ListenerFactory listenerFactory = new ListenerFactory();
	/** 数据传输工厂,在监听工厂使用 */
	DataConnectionConfigurationFactory dataConnectionConfigurationFactory = new DataConnectionConfigurationFactory();
	/**
	 * 如果不指定端口会WARN:<br/>
	 * <p>
	 * WARN org.apache.ftpserver.impl.PassivePorts - Releasing unreserved passive
	 * port: 41662
	 * </p>
	 */
	dataConnectionConfigurationFactory.setPassivePorts(storageServer.getPassivePorts());
	// /**强制不使用ip检查?不知道啥意思*/
	dataConnectionConfigurationFactory.setPassiveIpCheck(false);
	listenerFactory
			.setDataConnectionConfiguration(dataConnectionConfigurationFactory.createDataConnectionConfiguration());
	listenerFactory.setPort(storageServer.getPort());
	// if (storageServer.getSslEnable()) {
	// File keystoreFile = new File(Config.base(), "config/o2.keystore");
	// SslConfigurationFactory ssl = new SslConfigurationFactory();
	// ssl.setKeystoreFile(keystoreFile);
	// ssl.setKeystorePassword(Config.token().getSsl());
	// listenerFactory.setSslConfiguration(ssl.createSslConfiguration());
	// listenerFactory.setImplicitSsl(true);
	// }
	Listener listener = listenerFactory.createListener();
	serverFactory.addListener("default", listener);
	serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig());
	serverFactory.setUserManager(calculateUserManager(storageServer.getCalculatedAccounts()));
	FtpServer server = serverFactory.createServer();
	server.start();
	System.out.println("****************************************");
	System.out.println("* storage server start completed.");
	System.out.println("* port: " + storageServer.getPort() + ".");
	System.out.println("****************************************");
	return server;
}
 
Example #10
Source Project: wildfly-camel   Author: wildfly-extras   File: FtpIntegrationTest.java    License: Apache License 2.0 4 votes vote down vote up
@Before
public void startFtpServer() throws Exception {

    FileUtils.deleteDirectory(resolvePath(FTP_ROOT_DIR));

    File usersFile = USERS_FILE.toFile();
    usersFile.createNewFile();

    NativeFileSystemFactory fsf = new NativeFileSystemFactory();
    fsf.setCreateHome(true);

    PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
    pumf.setAdminName("admin");
    pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
    pumf.setFile(usersFile);

    UserManager userMgr = pumf.createUserManager();

    BaseUser user = new BaseUser();
    user.setName("admin");
    user.setPassword("admin");
    user.setHomeDirectory(FTP_ROOT_DIR.toString());

    List<Authority> authorities = new ArrayList<>();
    WritePermission writePermission = new WritePermission();
    writePermission.authorize(new WriteRequest());
    authorities.add(writePermission);
    user.setAuthorities(authorities);
    userMgr.save(user);

    ListenerFactory factory1 = new ListenerFactory();
    factory1.setPort(PORT);

    FtpServerFactory serverFactory = new FtpServerFactory();
    serverFactory.setUserManager(userMgr);
    serverFactory.setFileSystem(fsf);
    serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
    serverFactory.addListener("default", factory1.createListener());

    FtpServerFactory factory = serverFactory;
    ftpServer = factory.createServer();
    ftpServer.start();
}