org.apache.ftpserver.listener.ListenerFactory Java Examples
The following examples show how to use
org.apache.ftpserver.listener.ListenerFactory.
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: AbstractFTPTest.java From cyberduck with GNU General Public License v3.0 | 7 votes |
@Before public void start() throws Exception { final FtpServerFactory serverFactory = new FtpServerFactory(); final PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); final UserManager userManager = userManagerFactory.createUserManager(); BaseUser user = new BaseUser(); user.setName("test"); user.setPassword("test"); user.setHomeDirectory(new TemporaryApplicationResourcesFinder().find().getAbsolute()); List<Authority> authorities = new ArrayList<Authority>(); authorities.add(new WritePermission()); //authorities.add(new ConcurrentLoginPermission(2, Integer.MAX_VALUE)); user.setAuthorities(authorities); userManager.save(user); serverFactory.setUserManager(userManager); final ListenerFactory factory = new ListenerFactory(); factory.setPort(PORT_NUMBER); serverFactory.addListener("default", factory.createListener()); server = serverFactory.createServer(); server.start(); }
Example #2
Source File: FtpServerBean.java From camelinaction with Apache License 2.0 | 6 votes |
public static void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }
Example #3
Source File: CamelFtpsTest.java From jbpm-work-items with Apache License 2.0 | 6 votes |
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 #4
Source File: FtpServerBean.java From camelinaction with Apache License 2.0 | 6 votes |
public static void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }
Example #5
Source File: PFtpServer.java From PHONK with GNU General Public License v3.0 | 6 votes |
public void start() { FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); factory.setPort(mPort); // replace the default listener serverFactory.addListener("default", factory.createListener()); serverFactory.setUserManager(um); Map ftpLets = new HashMap<>(); ftpLets.put("ftpLet", new CallbackFTP(mCallback)); serverFactory.setFtplets(ftpLets); // start the server try { server = serverFactory.createServer(); server.start(); MLog.d(TAG, "server started"); } catch (FtpException e) { e.printStackTrace(); MLog.d(TAG, "server not started"); } }
Example #6
Source File: FtpServer.java From ProjectX with Apache License 2.0 | 6 votes |
/** * 创建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 #7
Source File: FtpServerBean.java From camelinaction2 with Apache License 2.0 | 6 votes |
public static void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }
Example #8
Source File: FtpServerBean.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }
Example #9
Source File: FtpServerBean.java From camelinaction2 with Apache License 2.0 | 6 votes |
public static void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }
Example #10
Source File: FtpServer.java From ProjectX with Apache License 2.0 | 6 votes |
/** * 创建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 #11
Source File: FtpServer.java From ProjectX with Apache License 2.0 | 6 votes |
/** * 创建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 #12
Source File: FtpProviderTestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates and starts an embedded Apache FTP Server (MINA). * * @param rootDirectory the local FTP server rootDirectory * @param fileSystemFactory optional local FTP server FileSystemFactory * @throws FtpException * @throws IOException */ static void setUpClass(final String rootDirectory, final FileSystemFactory fileSystemFactory) throws FtpException, IOException { if (Server != null) { return; } init(); final FtpServerFactory serverFactory = new FtpServerFactory(); final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory(); final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES); Assert.assertNotNull(USER_PROPS_RES, userPropsResource); propertiesUserManagerFactory.setUrl(userPropsResource); final UserManager userManager = propertiesUserManagerFactory.createUserManager(); final BaseUser user = (BaseUser) userManager.getUserByName("test"); // Pickup the home dir value at runtime even though we have it set in the user prop file // The user prop file requires the "homedirectory" to be set user.setHomeDirectory(rootDirectory); userManager.save(user); serverFactory.setUserManager(userManager); if (fileSystemFactory != null) { serverFactory.setFileSystem(fileSystemFactory); } final ListenerFactory factory = new ListenerFactory(); // set the port of the listener factory.setPort(SocketPort); // replace the default listener serverFactory.addListener("default", factory.createListener()); // start the server Server = serverFactory.createServer(); Server.start(); }
Example #13
Source File: GFtpServerFactory.java From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 | 5 votes |
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 #14
Source File: AntHarnessTest.java From ExpectIt with Apache License 2.0 | 5 votes |
@BeforeClass public static void startFtpServer() throws FtpException { FtpServerFactory serverFactory = new FtpServerFactory(); BaseUser user = new BaseUser(); user.setName("ftp"); user.setPassword("secret"); serverFactory.getUserManager().save(user); ListenerFactory factory = new ListenerFactory(); factory.setPort(0); Listener listener = factory.createListener(); serverFactory.addListener("default", listener); ftpServer = serverFactory.createServer(); ftpServer.start(); ftpPort = listener.getPort(); }
Example #15
Source File: FtpServer.java From ProjectX with Apache License 2.0 | 5 votes |
/** * 创建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 #16
Source File: FtpServer.java From ProjectX with Apache License 2.0 | 5 votes |
/** * 创建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 #17
Source File: FTPServer.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * 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 #18
Source File: FtpTestSupport.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@BeforeClass public static void createServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); serverFactory.setUserManager(new TestUserManager(remoteTemporaryFolder.getRoot().getAbsolutePath())); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); server = serverFactory.createServer(); server.start(); }
Example #19
Source File: FtpsProvider.java From product-ei with Apache License 2.0 | 5 votes |
/** * Creates and starts an embedded Apache FTPS Server (MINA). * * @throws FtpException * @throws IOException */ static void startFtpsServer() throws FtpException, IOException { if (Server != null) { return; } init(); final FtpServerFactory serverFactory = new FtpServerFactory(); final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory(); final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES); Assert.assertNotNull(USER_PROPS_RES, userPropsResource); propertiesUserManagerFactory.setUrl(userPropsResource); final UserManager userManager = propertiesUserManagerFactory.createUserManager(); serverFactory.setUserManager(userManager); final ListenerFactory factory = new ListenerFactory(); // set the port of the listener factory.setPort(SocketPort); // define SSL configuration final URL serverJksResource = ClassLoader.getSystemClassLoader().getResource(SERVER_JKS_RES); Assert.assertNotNull(SERVER_JKS_RES, serverJksResource); final SslConfigurationFactory ssl = new SslConfigurationFactory(); final File keyStoreFile = FileUtils.toFile(serverJksResource); Assert.assertTrue(keyStoreFile.toString(), keyStoreFile.exists()); ssl.setKeystoreFile(keyStoreFile); ssl.setKeystorePassword(Constants.KEYSTORE_PASSWORD); factory.setSslConfiguration(ssl.createSslConfiguration()); serverFactory.addListener("default", factory.createListener()); // start the server Server = serverFactory.createServer(); Server.start(); }
Example #20
Source File: FtpTestSupport.java From syndesis with Apache License 2.0 | 5 votes |
@Bean public FtpServer ftpTestServer(DataConnectionConfiguration dataConnectionConfiguration) { FtpEndpointConfiguration endpointConfiguration = new FtpEndpointConfiguration(); endpointConfiguration.setAutoConnect(true); endpointConfiguration.setAutoLogin(true); endpointConfiguration.setAutoHandleCommands( String.join(",", FTPCmd.PORT.getCommand(), FTPCmd.MKD.getCommand(), FTPCmd.PWD.getCommand(), FTPCmd.CWD.getCommand(), FTPCmd.PASV.getCommand(), FTPCmd.NOOP.getCommand(), FTPCmd.SYST.getCommand(), FTPCmd.LIST.getCommand(), FTPCmd.NLST.getCommand(), FTPCmd.QUIT.getCommand(), FTPCmd.TYPE.getCommand())); endpointConfiguration.setPort(FTP_TEST_SERVER_PORT); FtpServer ftpServer = new FtpServer(endpointConfiguration); ftpServer.setUserManagerProperties(new ClassPathResource("ftp.server.properties", FtpTestSupport.class)); ftpServer.setAutoStart(true); ListenerFactory listenerFactory = new ListenerFactory(); listenerFactory.setDataConnectionConfiguration(dataConnectionConfiguration); ftpServer.setListenerFactory(listenerFactory); return ftpServer; }
Example #21
Source File: CamelFtpsTest.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@Override protected FtpServer configureFtpServer(CamelFtpBaseTest.FtpServerBuilder builder) throws FtpException { ListenerFactory listenerFactory = configureSSL(); return builder.addUser(USER, PASSWD, ftpRoot, true).registerDefaultListener(listenerFactory.createListener()).build(); }
Example #22
Source File: CamelFtpTest.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@Override protected FtpServer configureFtpServer(CamelFtpBaseTest.FtpServerBuilder builder) throws FtpException { ListenerFactory listenerFactory = new ListenerFactory(); listenerFactory.setServerAddress(HOST); listenerFactory.setPort(PORT); return builder.addUser(USER, PASSWD, ftpRoot, true).registerDefaultListener(listenerFactory.createListener()).build(); }
Example #23
Source File: FtpsServer.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private FtpServer createServer( int port, String username, String password, boolean implicitSsl ) throws Exception { ListenerFactory factory = new ListenerFactory(); factory.setPort( port ); if ( implicitSsl ) { SslConfigurationFactory ssl = new SslConfigurationFactory(); ssl.setKeystoreFile( new File( SERVER_KEYSTORE ) ); ssl.setKeystorePassword( PASSWORD ); // set the SSL configuration for the listener factory.setSslConfiguration( ssl.createSslConfiguration() ); factory.setImplicitSsl( true ); } FtpServerFactory serverFactory = new FtpServerFactory(); // replace the default listener serverFactory.addListener( "default", factory.createListener() ); PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); userManagerFactory.setFile( new File( SERVER_USERS ) ); UserManager userManager = userManagerFactory.createUserManager(); if ( !userManager.doesExist( username ) ) { BaseUser user = new BaseUser(); user.setName( username ); user.setPassword( password ); user.setEnabled( true ); user.setHomeDirectory( USER_HOME_DIR ); user.setAuthorities( Collections.<Authority>singletonList( new WritePermission() ) ); userManager.save( user ); } serverFactory.setUserManager( userManager ); return serverFactory.createServer(); }
Example #24
Source File: FtpIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@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(); }
Example #25
Source File: FTPTestSupport.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override protected void setUp() throws Exception { if (ftpHomeDirFile.getParentFile().exists()) { IOHelper.deleteFile(ftpHomeDirFile.getParentFile()); } ftpHomeDirFile.mkdirs(); ftpHomeDirFile.getParentFile().deleteOnExit(); FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); UserManager userManager = userManagerFactory.createUserManager(); BaseUser user = new BaseUser(); user.setName("activemq"); user.setPassword("activemq"); user.setHomeDirectory(ftpHomeDirFile.getParent()); // authorize user List<Authority> auths = new ArrayList<>(); Authority auth = new WritePermission(); auths.add(auth); user.setAuthorities(auths); userManager.save(user); BaseUser guest = new BaseUser(); guest.setName("guest"); guest.setPassword("guest"); guest.setHomeDirectory(ftpHomeDirFile.getParent()); userManager.save(guest); serverFactory.setUserManager(userManager); factory.setPort(0); serverFactory.addListener(ftpServerListenerName, factory.createListener()); server = serverFactory.createServer(); server.start(); ftpPort = serverFactory.getListener(ftpServerListenerName).getPort(); super.setUp(); }
Example #26
Source File: AbstractFtpsProviderTestCase.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Creates and starts an embedded Apache FTP Server (MINA). * * @param implicit FTPS connection mode * @throws FtpException * @throws IOException */ static void setUpClass(final boolean implicit) throws FtpException, IOException { if (Server != null) { return; } init(); final FtpServerFactory serverFactory = new FtpServerFactory(); final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory(); final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES); Assert.assertNotNull(USER_PROPS_RES, userPropsResource); propertiesUserManagerFactory.setUrl(userPropsResource); final UserManager userManager = propertiesUserManagerFactory.createUserManager(); final BaseUser user = (BaseUser) userManager.getUserByName("test"); // Pickup the home dir value at runtime even though we have it set in the user prop file // The user prop file requires the "homedirectory" to be set user.setHomeDirectory(getTestDirectory()); serverFactory.setUserManager(userManager); final ListenerFactory factory = new ListenerFactory(); // set the port of the listener factory.setPort(SocketPort); // define SSL configuration final URL serverJksResource = ClassLoader.getSystemClassLoader().getResource(SERVER_JKS_RES); Assert.assertNotNull(SERVER_JKS_RES, serverJksResource); final SslConfigurationFactory ssl = new SslConfigurationFactory(); final File keyStoreFile = FileUtils.toFile(serverJksResource); Assert.assertTrue(keyStoreFile.toString(), keyStoreFile.exists()); ssl.setKeystoreFile(keyStoreFile); ssl.setKeystorePassword("password"); // set the SSL configuration for the listener factory.setSslConfiguration(ssl.createSslConfiguration()); factory.setImplicitSsl(implicit); // replace the default listener serverFactory.addListener("default", factory.createListener()); // start the server Server = serverFactory.createServer(); Server.start(); }
Example #27
Source File: FtpTestResource.java From camel-quarkus with Apache License 2.0 | 4 votes |
@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 #28
Source File: StorageServerTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
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; }