FtpClient extends AbstractEndpoint implements Producer, ReplyConsumer, InitializingBean, DisposableBean { protected FtpMessage retrieveFile(GetCommand command, TestContext context) { try { String remoteFilePath = context.replaceDynamicContentInString(command.getFile().getPath()); String localFilePath = addFileNameToTargetPath(remoteFilePath, context.replaceDynamicContentInString(command.getTarget().getPath())); if (Paths.get(localFilePath).getParent() != null) { Files.createDirectories(Paths.get(localFilePath).getParent()); } String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElse(DataType.BINARY.name())); try (FileOutputStream localFileOutputStream = new FileOutputStream(localFilePath)) { ftpClient.setFileType(getFileType(dataType)); if (!ftpClient.retrieveFile(remoteFilePath, localFileOutputStream)) { throw new CitrusRuntimeException("Failed to get file from FTP server. Remote path: " + remoteFilePath + ". Local file path: " + localFilePath + ". FTP reply: " + ftpClient.getReplyString()); } } if (getEndpointConfiguration().isAutoReadFiles()) { String fileContent; if (command.getFile().getType().equals(DataType.BINARY.name())) { fileContent = Base64.encodeBase64String(FileCopyUtils.copyToByteArray(FileUtils.getFileResource(localFilePath).getInputStream())); } else { fileContent = FileUtils.readToString(FileUtils.getFileResource(localFilePath)); } return FtpMessage.result(ftpClient.getReplyCode(), ftpClient.getReplyString(), localFilePath, fileContent); } else { return FtpMessage.result(ftpClient.getReplyCode(), ftpClient.getReplyString(), localFilePath, null); } } catch (IOException e) { throw new CitrusRuntimeException("Failed to get file from FTP server", e); } } FtpClient(); protected  FtpClient(FtpEndpointConfiguration endpointConfiguration); @Override FtpEndpointConfiguration getEndpointConfiguration(); @Override void send(Message message, TestContext context); @Override Message receive(TestContext context); @Override Message receive(String selector, TestContext context); @Override Message receive(TestContext context, long timeout); @Override Message receive(String selector, TestContext context, long timeout); @Override void afterPropertiesSet(); @Override void destroy(); @Override Producer createProducer(); @Override SelectiveConsumer createConsumer(); void setFtpClient(FTPClient ftpClient); FTPClient getFtpClient(); void setCorrelationManager(CorrelationManager<Message> correlationManager);  }
@Test public void testRetrieveFile() { assertTrue(fakeFtpServer.getFileSystem().exists(DOWNLOAD_FILE)); String localFilePath = Paths.get(targetPath, "download_file").toString(); ftpClient.retrieveFile(getCommand(DOWNLOAD_FILE, localFilePath), context); assertTrue(fakeFtpServer.getFileSystem().exists(DOWNLOAD_FILE)); assertTrue(new File(localFilePath).exists()); }
@Test public void testRetrieveFileImplicitFilename() { assertTrue(fakeFtpServer.getFileSystem().exists(DOWNLOAD_FILE)); ftpClient.retrieveFile(getCommand(DOWNLOAD_FILE, targetPath + "/"), context); assertTrue(fakeFtpServer.getFileSystem().exists(DOWNLOAD_FILE)); assertTrue(new File(targetPath + DOWNLOAD_FILE).exists()); }