Search in sources :

Example 6 with FTPSClient

use of org.apache.commons.net.ftp.FTPSClient in project ddf by codice.

the class TestFtp method testFtpsMkdirCwdPutFile.

@Test
public void testFtpsMkdirCwdPutFile() throws Exception {
    setClientAuthConfiguration(NEED);
    FTPSClient client = createSecureClient(true);
    String newDir = "newDirectory";
    String finalFilename = "test.txt";
    boolean ret = client.makeDirectory(newDir);
    assertTrue(ret);
    ret = client.changeWorkingDirectory(newDir);
    assertTrue(ret);
    ftpPut(client, SAMPLE_DATA, finalFilename);
    verifyIngest(1, finalFilename);
}
Also used : FTPSClient(org.apache.commons.net.ftp.FTPSClient) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with FTPSClient

use of org.apache.commons.net.ftp.FTPSClient in project ddf by codice.

the class TestFtp method createSecureClient.

private FTPSClient createSecureClient(boolean setKeystore) throws Exception {
    FTPSClient ftps = new FTPSClient();
    if (setKeystore) {
        KeyManager keyManager = KeyManagerUtils.createClientKeyManager(new File(System.getProperty("javax.net.ssl.keyStore")), System.getProperty("javax.net.ssl.keyStorePassword"));
        ftps.setKeyManager(keyManager);
    }
    int attempts = 0;
    while (true) {
        try {
            ftps.connect(FTP_SERVER, Integer.parseInt(FTP_PORT.getPort()));
            break;
        } catch (SocketException e) {
            //a socket exception can be thrown if the ftp server is still in the process of coming up or down
            Thread.sleep(1000);
            if (attempts++ > 30) {
                throw e;
            }
        }
    }
    showServerReply(ftps);
    int connectionReply = ftps.getReplyCode();
    if (!FTPReply.isPositiveCompletion(connectionReply)) {
        fail("FTP server refused connection: " + connectionReply);
    }
    boolean success = ftps.login(USERNAME, PASSWORD);
    showServerReply(ftps);
    if (!success) {
        fail("Could not log in to the FTP server.");
    }
    ftps.enterLocalPassiveMode();
    ftps.setControlKeepAliveTimeout(300);
    ftps.setFileType(FTP.BINARY_FILE_TYPE);
    return ftps;
}
Also used : SocketException(java.net.SocketException) FTPSClient(org.apache.commons.net.ftp.FTPSClient) KeyManager(javax.net.ssl.KeyManager) File(java.io.File)

Aggregations

FTPSClient (org.apache.commons.net.ftp.FTPSClient)7 File (java.io.File)2 SocketException (java.net.SocketException)2 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 KeyManager (javax.net.ssl.KeyManager)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 SSLContext (javax.net.ssl.SSLContext)1 SSLException (javax.net.ssl.SSLException)1 SSLSocket (javax.net.ssl.SSLSocket)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 JndiRegistry (org.apache.camel.impl.JndiRegistry)1 FTPClientConfig (org.apache.commons.net.ftp.FTPClientConfig)1 FTPConnectionClosedException (org.apache.commons.net.ftp.FTPConnectionClosedException)1 FTPFile (org.apache.commons.net.ftp.FTPFile)1