SftpClient extends FtpClient { @Override protected FtpMessage listFiles(ListCommand list, TestContext context) { String remoteFilePath = Optional.ofNullable(list.getTarget()) .map(ListCommand.Target::getPath) .map(context::replaceDynamicContentInString) .orElse(""); try { List<String> fileNames = new ArrayList<>(); Vector<ChannelSftp.LsEntry> entries = sftp.ls(remoteFilePath); for (ChannelSftp.LsEntry entry : entries) { fileNames.add(entry.getFilename()); } return FtpMessage.result(FTPReply.FILE_STATUS_OK, "List files complete", fileNames); } catch (SftpException e) { throw new CitrusRuntimeException(String.format("Failed to list files in path '%s'", remoteFilePath), e); } } SftpClient(); protected  SftpClient(SftpEndpointConfiguration endpointConfiguration); @Override SftpEndpointConfiguration getEndpointConfiguration(); @Override void afterPropertiesSet(); @Override void destroy(); JSch getSsh(); void setSsh(JSch ssh);  }
@Test public void testListFiles() { String remoteFilePath = targetPath + "/file1"; FtpMessage ftpMessage = sftpClient.storeFile(putCommand(localFilePath, remoteFilePath), context); verifyMessage(ftpMessage, PutCommandResult.class, CLOSING_DATA_CONNECTION, "Transfer complete"); assertTrue(Paths.get(remoteFilePath).toFile().exists()); remoteFilePath = targetPath + "/file2"; ftpMessage = sftpClient.storeFile(putCommand(localFilePath, remoteFilePath), context); verifyMessage(ftpMessage, PutCommandResult.class, CLOSING_DATA_CONNECTION, "Transfer complete"); assertTrue(Paths.get(remoteFilePath).toFile().exists()); ftpMessage = sftpClient.listFiles(listCommand(targetPath + "/file*"), context); verifyMessage(ftpMessage, ListCommandResult.class, FILE_STATUS_OK, "List files complete", Arrays.asList("file1", "file2")); assertTrue(Paths.get(targetPath + "/file1").toFile().exists()); assertTrue(Paths.get(targetPath + "/file2").toFile().exists()); }