Search in sources :

Example 6 with FtpServer

use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.

the class FtpClientTest method test_doGet_file_with_space.

public void test_doGet_file_with_space() 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 + "/text 3.txt");
        assertEquals(200, responseData.getHttpStatusCode());
        assertEquals("UTF-8", responseData.getCharSet());
        assertEquals(6, responseData.getContentLength());
        assertNotNull(responseData.getLastModified());
        assertEquals(Constants.GET_METHOD, responseData.getMethod());
        assertEquals("text/plain", responseData.getMimeType());
        assertTrue(responseData.getUrl().endsWith("text 3.txt"));
        final String content = new String(InputStreamUtil.getBytes(responseData.getResponseBody()), "UTF-8");
        assertEquals("test3\n", content);
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : HashMap(java.util.HashMap) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) FtpServer(org.apache.ftpserver.FtpServer)

Example 7 with FtpServer

use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.

the class FtpClientTest method test_doGet_root_dir.

public void test_doGet_root_dir() throws FtpException {
    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);
        ftpClient.doGet("ftp://localhost:" + FTP_PORT + "/");
        fail();
    } catch (final ChildUrlsException e) {
        final Set<RequestData> urlSet = e.getChildUrlList();
        assertEquals(5, urlSet.size());
        for (final RequestData requestData : urlSet.toArray(new RequestData[urlSet.size()])) {
            String url = requestData.getUrl();
            assertTrue(url.contains("dir1") || url.contains("dir2") || url.contains("text1.txt") || url.contains("text2.txt") || url.contains("text 3.txt"));
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) Set(java.util.Set) HashMap(java.util.HashMap) RequestData(org.codelibs.fess.crawler.entity.RequestData) FtpServer(org.apache.ftpserver.FtpServer)

Example 8 with FtpServer

use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.

the class FtpClientTest method test_doGet_dir1.

public void test_doGet_dir1() throws FtpException {
    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);
        ftpClient.doGet("ftp://localhost:" + FTP_PORT + "/dir1");
        fail();
    } catch (final ChildUrlsException e) {
        final Set<RequestData> urlSet = e.getChildUrlList();
        assertEquals(1, urlSet.size());
        for (final RequestData requestData : urlSet.toArray(new RequestData[urlSet.size()])) {
            String url = requestData.getUrl();
            assertTrue(url.contains("dir1/test3.txt"));
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) Set(java.util.Set) HashMap(java.util.HashMap) RequestData(org.codelibs.fess.crawler.entity.RequestData) FtpServer(org.apache.ftpserver.FtpServer)

Example 9 with FtpServer

use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.

the class FtpClientTest method test_doHead_file.

public void test_doHead_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.doHead("ftp://localhost:" + FTP_PORT + "/text1.txt");
        assertNotNull(responseData.getLastModified());
        assertTrue(responseData.getLastModified().getTime() < new Date().getTime());
        assertNull(responseData.getResponseBody());
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : HashMap(java.util.HashMap) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) FtpServer(org.apache.ftpserver.FtpServer) Date(java.util.Date)

Aggregations

FtpServer (org.apache.ftpserver.FtpServer)9 HashMap (java.util.HashMap)7 ResponseData (org.codelibs.fess.crawler.entity.ResponseData)5 Set (java.util.Set)2 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)2 UserManager (org.apache.ftpserver.ftplet.UserManager)2 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)2 BaseUser (org.apache.ftpserver.usermanager.impl.BaseUser)2 RequestData (org.codelibs.fess.crawler.entity.RequestData)2 ChildUrlsException (org.codelibs.fess.crawler.exception.ChildUrlsException)2 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 FtpException (org.apache.ftpserver.ftplet.FtpException)1 PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)1