use of org.apache.ftpserver.FtpServer in project alliance by codice.
the class MockNsili method startFtpWebServer.
public void startFtpWebServer(int port) {
FtpServerFactory ftpServerFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(port);
ftpServerFactory.addListener("default", listenerFactory.createListener());
PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
UserManager userManager = propertiesUserManagerFactory.createUserManager();
BaseUser baseUser = new BaseUser();
baseUser.setName(MOCK_SERVER_USERNAME);
baseUser.setPassword(MOCK_SERVER_PASSWORD);
try {
ftpHomeDirectoryPath = Files.createTempDirectory("home_");
Runtime.getRuntime().addShutdownHook(new Thread(() -> FileUtils.deleteQuietly(ftpHomeDirectoryPath.toFile())));
baseUser.setHomeDirectory(ftpHomeDirectoryPath.toString());
} catch (IOException e) {
LOGGER.info("Unable to set ftp endpoint to a temporary home directory.");
}
try {
userManager.save(baseUser);
ftpServerFactory.setUserManager(userManager);
FtpServer ftpServer = ftpServerFactory.createServer();
ftpServer.start();
} catch (FtpException e) {
LOGGER.error("Unable to start FTP server.", e);
}
LOGGER.info("Setting the ftp server's publish address to be ftp://localhost:{}/", port);
}
use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doHead_dir1.
public void test_doHead_dir1() throws Exception {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
final ResponseData responseData = ftpClient.doHead("ftp://localhost:" + FTP_PORT + "/dir1");
assertNull(responseData);
} finally {
if (server != null) {
server.stop();
}
}
}
use of org.apache.ftpserver.FtpServer 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.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doHead_root_dir.
public void test_doHead_root_dir() throws Exception {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
final ResponseData responseData = ftpClient.doHead("ftp://localhost:" + FTP_PORT + "/");
assertNull(responseData);
} finally {
if (server != null) {
server.stop();
}
}
}
use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doGet_file.
public void test_doGet_file() throws Exception {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
final ResponseData responseData = ftpClient.doGet("ftp://localhost:" + FTP_PORT + "/text1.txt");
assertEquals(200, responseData.getHttpStatusCode());
assertEquals("UTF-8", responseData.getCharSet());
assertTrue(6 == responseData.getContentLength());
assertNotNull(responseData.getLastModified());
assertEquals(Constants.GET_METHOD, responseData.getMethod());
assertEquals("text/plain", responseData.getMimeType());
assertTrue(responseData.getUrl().endsWith("text1.txt"));
final String content = new String(InputStreamUtil.getBytes(responseData.getResponseBody()), "UTF-8");
assertEquals("test1", content.trim());
} finally {
if (server != null) {
server.stop();
}
}
}
Aggregations