use of org.apache.ftpserver.FtpServerFactory in project activemq-artemis by apache.
the class FTPTestSupport method setUp.
@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();
}
use of org.apache.ftpserver.FtpServerFactory in project fess-crawler by codelibs.
the class FtpClientTest method startFtpServer.
public FtpServer startFtpServer(int port, String username, String password) throws FtpException {
FtpServerFactory factory = new FtpServerFactory();
ListenerFactory lisnerFactory = new ListenerFactory();
lisnerFactory.setPort(port);
factory.addListener("default", lisnerFactory.createListener());
if (username != null) {
UserManager userManager = factory.getUserManager();
BaseUser ftpUser = new BaseUser();
ftpUser.setName(username);
ftpUser.setPassword(password);
final File file = ResourceUtil.getResourceAsFile("test");
String path = file.getAbsolutePath();
ftpUser.setHomeDirectory(path);
userManager.save(ftpUser);
}
FtpServer server = factory.createServer();
server.start();
return server;
}
use of org.apache.ftpserver.FtpServerFactory in project quickstarts by jboss-switchyard.
the class CamelFtpBindingTest method startUp.
@BeforeClass
public static void startUp() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(2222);
serverFactory.addListener("default", listenerFactory.createListener());
ListenerFactory sslListenerFactory = new ListenerFactory();
sslListenerFactory.setPort(2221);
SslConfigurationFactory ssl = new SslConfigurationFactory();
ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
ssl.setKeystorePassword("password");
sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
// Setting it to true will not read the file
sslListenerFactory.setImplicitSsl(false);
serverFactory.addListener("ftps", sslListenerFactory.createListener());
PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
managerFactory.setFile(new File("src/test/resources/users.properties"));
UserManager createUserManager = managerFactory.createUserManager();
serverFactory.setUserManager(createUserManager);
NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
fileSystemFactory.setCreateHome(true);
serverFactory.setFileSystem(fileSystemFactory);
File file = new File("target/ftp/ftps");
file.mkdirs();
file = new File("target/ftp/sftp");
file.mkdirs();
ftpServer = serverFactory.createServer();
ftpServer.start();
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(2220);
sshd.setKeyPairProvider(createTestKeyPairProvider("src/test/resources/hostkey.pem"));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.start();
JSch sch = new JSch();
Session session = sch.getSession("camel", "localhost", 2220);
session.setUserInfo(new SimpleUserInfo("isMyFriend"));
session.connect();
ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
c.connect();
System.out.println("Home: " + c.getHome());
c.chmod(777, ".");
c.chmod(777, "target");
c.chmod(777, "target/ftp");
c.chmod(777, "target/ftp/sftp");
c.disconnect();
session.disconnect();
}
use of org.apache.ftpserver.FtpServerFactory in project pentaho-kettle by pentaho.
the class FtpsServer method createServer.
/*
* Adopted from https://mina.apache.org/ftpserver-project/embedding_ftpserver.html
*/
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();
}
use of org.apache.ftpserver.FtpServerFactory in project camel by apache.
the class SpringFtpEndpointTest method initFtpServer.
protected void initFtpServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
// setup user management to read our users.properties and use clear text passwords
File file = new File("src/test/resources/users.properties");
UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), file, "admin");
serverFactory.setUserManager(uman);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
serverFactory.setFileSystem(fsf);
ListenerFactory factory = new ListenerFactory();
factory.setPort(ftpPort);
serverFactory.addListener("default", factory.createListener());
ftpServer = serverFactory.createServer();
}
Aggregations