org.apache.ftpserver.DataConnectionConfigurationFactory Java Examples

The following examples show how to use org.apache.ftpserver.DataConnectionConfigurationFactory. 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 File: CamelFtpsTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
private ListenerFactory configureSSL() {
    ListenerFactory listener = new ListenerFactory();
    listener.setServerAddress("127.0.0.1");
    listener.setPort(PORT);

    SslConfigurationFactory ssl = new SslConfigurationFactory();
    ssl.setKeystoreFile(SERVER_SSL_KEY_TRUST_STORE);
    ssl.setKeyPassword(SERVER_SSL_KEY_PASSWD);
    ssl.setKeystorePassword(SERVER_SSL_STORE_PASSWD);
    ssl.setTruststoreFile(SERVER_SSL_KEY_TRUST_STORE);
    ssl.setTruststorePassword(SERVER_SSL_STORE_PASSWD);
    ssl.setClientAuthentication("NEED");

    SslConfiguration sslConfig = ssl.createSslConfiguration();

    listener.setSslConfiguration(sslConfig);
    listener.setImplicitSsl(true);
    DataConnectionConfigurationFactory dataConfigFactory = new DataConnectionConfigurationFactory();
    dataConfigFactory.setImplicitSsl(true);

    listener.setDataConnectionConfiguration(dataConfigFactory.createDataConnectionConfiguration());

    return listener;
}
 
Example #2
Source File: FtpServer.java    From ProjectX with 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 #3
Source File: FtpServer.java    From ProjectX with 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 #4
Source File: FtpServer.java    From ProjectX with 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 #5
Source File: FtpToDB_IT.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Bean
public DataConnectionConfiguration dataConnectionConfiguration() {
    DataConnectionConfigurationFactory dataConnectionFactory = new DataConnectionConfigurationFactory();
    dataConnectionFactory.setPassiveExternalAddress(integrationContainer.getInternalHostIp());
    dataConnectionFactory.setPassivePorts(String.valueOf(PASSIVE_PORT));
    return dataConnectionFactory.createDataConnectionConfiguration();
}
 
Example #6
Source File: FtpSplitToDB_IT.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Bean
public DataConnectionConfiguration dataConnectionConfiguration() {
    DataConnectionConfigurationFactory dataConnectionFactory = new DataConnectionConfigurationFactory();
    dataConnectionFactory.setPassiveExternalAddress(integrationContainer.getInternalHostIp());
    dataConnectionFactory.setPassivePorts(String.valueOf(PASSIVE_PORT));
    return dataConnectionFactory.createDataConnectionConfiguration();
}
 
Example #7
Source File: WebHookToFtp_IT.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Bean
public DataConnectionConfiguration dataConnectionConfiguration() {
    DataConnectionConfigurationFactory dataConnectionFactory = new DataConnectionConfigurationFactory();
    dataConnectionFactory.setPassiveExternalAddress(integrationContainer.getInternalHostIp());
    dataConnectionFactory.setPassivePorts(String.valueOf(PASSIVE_PORT));
    return dataConnectionFactory.createDataConnectionConfiguration();
}
 
Example #8
Source File: FtpServer.java    From ProjectX with 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 #9
Source File: FtpServer.java    From ProjectX with 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 #10
Source File: StorageServerTools.java    From o2oa with 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;
}