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);
}
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;
}
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;
}
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));
}
}
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());
}
Aggregations