Search in sources :

Example 16 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project ddf by codice.

the class FtpServerStarterTest method setup.

@Before
public void setup() {
    Ftplet ftplet = mock(FtpRequestHandler.class);
    ftpServerFactory = mock(FtpServerFactory.class);
    listenerFactory = mock(ListenerFactory.class);
    UserManager userManager = mock(UserManagerImpl.class);
    sslConfigurationFactory = mock(SslConfigurationFactory.class);
    defaultListener = mock(Listener.class);
    server = mock(DefaultFtpServer.class, RETURNS_DEEP_STUBS);
    sessions = new HashSet<>();
    ftpServerStarter = new FtpServerStarter(ftplet, ftpServerFactory, listenerFactory, userManager, sslConfigurationFactory);
}
Also used : DefaultFtpServer(org.apache.ftpserver.impl.DefaultFtpServer) Ftplet(org.apache.ftpserver.ftplet.Ftplet) Listener(org.apache.ftpserver.listener.Listener) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) Before(org.junit.Before)

Example 17 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project camel by apache.

the class FtpsServerTestSupport method doCreateFtpServerFactory.

protected FtpServerFactory doCreateFtpServerFactory() throws Exception {
    assertTrue(FTPSERVER_KEYSTORE.exists());
    FtpServerFactory serverFactory = super.createFtpServerFactory();
    ListenerFactory listenerFactory = new ListenerFactory(serverFactory.getListener(DEFAULT_LISTENER));
    listenerFactory.setImplicitSsl(useImplicit());
    listenerFactory.setSslConfiguration(createSslConfiguration().createSslConfiguration());
    serverFactory.addListener(DEFAULT_LISTENER, listenerFactory.createListener());
    return serverFactory;
}
Also used : FtpServerFactory(org.apache.ftpserver.FtpServerFactory) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 18 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project camel by apache.

the class FtpServerTestSupport method createFtpServerFactory.

protected FtpServerFactory createFtpServerFactory() throws Exception {
    assertTrue(USERS_FILE.exists());
    assertTrue("Port number is not initialized in an expected range: " + BaseServerTestSupport.port, BaseServerTestSupport.port >= 21000);
    NativeFileSystemFactory fsf = new NativeFileSystemFactory();
    fsf.setCreateHome(true);
    PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
    pumf.setAdminName("admin");
    pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
    pumf.setFile(USERS_FILE);
    UserManager userMgr = pumf.createUserManager();
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(BaseServerTestSupport.port);
    FtpServerFactory serverFactory = new FtpServerFactory();
    serverFactory.setUserManager(userMgr);
    serverFactory.setFileSystem(fsf);
    serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
    serverFactory.addListener(DEFAULT_LISTENER, factory.createListener());
    return serverFactory;
}
Also used : UserManager(org.apache.ftpserver.ftplet.UserManager) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) ConnectionConfigFactory(org.apache.ftpserver.ConnectionConfigFactory) ClearTextPasswordEncryptor(org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 19 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project AmazeFileManager by TeamAmaze.

the class FTPService method run.

@Override
public void run() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    FtpServerFactory serverFactory = new FtpServerFactory();
    ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
    connectionConfigFactory.setAnonymousLoginEnabled(true);
    serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig());
    String usernamePreference = preferences.getString(KEY_PREFERENCE_USERNAME, DEFAULT_USERNAME);
    if (!usernamePreference.equals(DEFAULT_USERNAME)) {
        username = usernamePreference;
        try {
            password = CryptUtil.decryptPassword(getApplicationContext(), preferences.getString(KEY_PREFERENCE_PASSWORD, ""));
            isPasswordProtected = true;
        } catch (GeneralSecurityException | IOException e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), getResources().getString(R.string.error), Toast.LENGTH_SHORT).show();
            // can't decrypt the password saved in preferences, remove the preference altogether
            // and start an anonymous connection instead
            preferences.edit().putString(FTPService.KEY_PREFERENCE_PASSWORD, "").apply();
            isPasswordProtected = false;
        }
    }
    BaseUser user = new BaseUser();
    if (!isPasswordProtected) {
        user.setName("anonymous");
    } else {
        user.setName(username);
        user.setPassword(password);
    }
    user.setHomeDirectory(preferences.getString(KEY_PREFERENCE_PATH, DEFAULT_PATH));
    List<Authority> list = new ArrayList<>();
    list.add(new WritePermission());
    user.setAuthorities(list);
    try {
        serverFactory.getUserManager().save(user);
    } catch (FtpException e) {
        e.printStackTrace();
    }
    ListenerFactory fac = new ListenerFactory();
    if (preferences.getBoolean(KEY_PREFERENCE_SECURE, DEFAULT_SECURE)) {
        SslConfigurationFactory sslConfigurationFactory = new SslConfigurationFactory();
        File file;
        try {
            InputStream stream = getResources().openRawResource(R.raw.key);
            file = File.createTempFile("keystore.bks", "");
            FileOutputStream outputStream = new FileOutputStream(file);
            IOUtils.copy(stream, outputStream);
        } catch (Exception e) {
            e.printStackTrace();
            file = null;
        }
        if (file != null) {
            sslConfigurationFactory.setKeystoreFile(file);
            sslConfigurationFactory.setKeystorePassword("vishal007");
            fac.setSslConfiguration(sslConfigurationFactory.createSslConfiguration());
            fac.setImplicitSsl(true);
        } else {
            // no keystore found
            preferences.edit().putBoolean(KEY_PREFERENCE_SECURE, false).apply();
        }
    }
    fac.setPort(getPort(preferences));
    fac.setIdleTimeout(preferences.getInt(KEY_PREFERENCE_TIMEOUT, DEFAULT_TIMEOUT));
    serverFactory.addListener("default", fac.createListener());
    try {
        server = serverFactory.createServer();
        server.start();
        sendBroadcast(new Intent(FTPService.ACTION_STARTED).putExtra(TAG_STARTED_BY_TILE, isStartedByTile));
    } catch (Exception e) {
        sendBroadcast(new Intent(FTPService.ACTION_FAILEDTOSTART));
    }
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) SharedPreferences(android.content.SharedPreferences) Authority(org.apache.ftpserver.ftplet.Authority) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) InputStream(java.io.InputStream) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ConnectionConfigFactory(org.apache.ftpserver.ConnectionConfigFactory) IOException(java.io.IOException) WritePermission(org.apache.ftpserver.usermanager.impl.WritePermission) SocketException(java.net.SocketException) GeneralSecurityException(java.security.GeneralSecurityException) FtpException(org.apache.ftpserver.ftplet.FtpException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileOutputStream(java.io.FileOutputStream) FtpException(org.apache.ftpserver.ftplet.FtpException) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) File(java.io.File) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 20 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project spring-integration-samples by spring-projects.

the class TestSuite method setupFtpServer.

@BeforeClass
public static void setupFtpServer() throws FtpException, IOException {
    Integer availableServerSocket;
    if (System.getProperty(SERVER_PORT_SYSTEM_PROPERTY) == null) {
        availableServerSocket = 0;
    } else {
        availableServerSocket = Integer.valueOf(System.getProperty(SERVER_PORT_SYSTEM_PROPERTY));
    }
    File ftpRoot = new File(FTP_ROOT_DIR);
    ftpRoot.mkdirs();
    TestUserManager userManager = new TestUserManager(ftpRoot.getAbsolutePath());
    FtpServerFactory serverFactory = new FtpServerFactory();
    serverFactory.setUserManager(userManager);
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(availableServerSocket);
    factory.setIdleTimeout(600);
    serverFactory.addListener("default", factory.createListener());
    server = serverFactory.createServer();
    server.start();
    Listener listener = serverFactory.getListeners().values().iterator().next();
    availableServerSocket = listener.getPort();
    LOGGER.info("Using open server port..." + availableServerSocket);
    System.setProperty(SERVER_PORT_SYSTEM_PROPERTY, availableServerSocket.toString());
}
Also used : Listener(org.apache.ftpserver.listener.Listener) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) File(java.io.File) TestUserManager(org.springframework.integration.samples.ftp.support.TestUserManager) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

FtpServerFactory (org.apache.ftpserver.FtpServerFactory)22 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)20 UserManager (org.apache.ftpserver.ftplet.UserManager)13 File (java.io.File)11 NativeFileSystemFactory (org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory)8 ClearTextPasswordEncryptor (org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor)8 BaseUser (org.apache.ftpserver.usermanager.impl.BaseUser)7 PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)6 ConnectionConfigFactory (org.apache.ftpserver.ConnectionConfigFactory)5 PropertiesUserManager (org.apache.ftpserver.usermanager.impl.PropertiesUserManager)5 WritePermission (org.apache.ftpserver.usermanager.impl.WritePermission)5 ArrayList (java.util.ArrayList)4 Authority (org.apache.ftpserver.ftplet.Authority)4 SslConfigurationFactory (org.apache.ftpserver.ssl.SslConfigurationFactory)4 IOException (java.io.IOException)3 FtpException (org.apache.ftpserver.ftplet.FtpException)3 Listener (org.apache.ftpserver.listener.Listener)3 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 FtpServer (org.apache.ftpserver.FtpServer)2