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