use of com.fo0.robot.connector.FTPClient in project Robot by fo0.
the class FTPClientTest method downloadFTPFile.
@Test
public void downloadFTPFile() {
FTPClient client = new FTPClient(Host.builder().address(FTP_ADDRESS).port(21).username("anonymous").password("").build());
boolean connected = client.connect();
System.out.println("connected: " + connected);
Assert.assertEquals(true, connected);
FileTransferData f = client.download("test/1MB.zip", FTP_FILE_NAME);
Assert.assertNotNull(f);
Assert.assertEquals(FTP_FILE_NAME, new File(f.getLocalPath()).getName());
Assert.assertEquals(1048576, f.getSize());
new File(f.getLocalPath()).deleteOnExit();
}
use of com.fo0.robot.connector.FTPClient in project Robot by fo0.
the class ChainActionItem method ftp.
public EChainResponse ftp(List<KeyValue> list) throws Exception {
List<KeyValue> ftpList = list;
KeyValue ftpHost = ftpList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.HOST)).findFirst().orElse(null);
KeyValue ftpPort = ftpList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.PORT)).findFirst().orElse(KeyValue.builder().key("PORT").value("21").build());
KeyValue ftpUser = ftpList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.USER)).findFirst().orElse(KeyValue.builder().key("USER").value("anonymous").build());
KeyValue ftpPassword = ftpList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.PASSWORD)).findFirst().orElse(KeyValue.builder().key("PASSWORD").value("").build());
KeyValue ftpSrc = ftpList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.SOURCE)).findFirst().orElse(null);
KeyValue ftpDst = ftpList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.DESTINATION)).findFirst().orElse(null);
ctx.addToLog(type, "HOST: " + ftpHost.getValue());
ctx.addToLog(type, "PORT: " + ftpPort.getValue());
ctx.addToLog(type, "User: " + ftpUser.getValue());
ctx.addToLog(type, "Password: " + StringUtils.join(IntStream.range(0, ftpPassword.getValue().length()).mapToObj(e -> "*").toArray(String[]::new)));
ctx.addToLog(type, "SRC: " + ftpSrc.getValue());
ctx.addToLog(type, "DST: " + ftpDst.getValue());
FTPClient ftpClient = new FTPClient(Host.builder().address(ftpHost.getValue()).port(Integer.parseInt(ftpPort.getValue())).username(ftpUser.getValue()).password(ftpPassword.getValue()).build());
if (!ftpClient.connect()) {
ctx.addToLog(type, "failed to connect to Host");
return EChainResponse.Failed;
}
FileTransferData ftpData = ftpClient.download(ftpDst.getValue(), ftpSrc.getValue());
try {
ctx.addToLog(type, "Transfer: " + ftpData.info());
} catch (Exception e2) {
e2.printStackTrace();
}
return EChainResponse.Continue;
}
Aggregations