src/main/java/uk/gov/hmcts/reform/sendletter/services/ftp/FtpClient.java
@Dependency(name = FTP_CLIENT, command = FTP_REPORT_DOWNLOADED, type = FTP)
    public List<Report> downloadReports() {
        logger.info("Downloading reports from SFTP server");

        return runWith(sftp -> {
            try {
                SFTPFileTransfer transfer = sftp.getFileTransfer();

                List<Report> reports = sftp.ls(configProperties.getReportsFolder())
                    .stream()
                    .filter(this::isReportFile)
                    .map(file -> {
                        InMemoryDownloadedFile inMemoryFile = new InMemoryDownloadedFile();
                        try {
                            transfer.download(file.getPath(), inMemoryFile);
                            Report report = new Report(file.getPath(), inMemoryFile.getBytes());
                            logger.info("Downloaded report file '{}'", report.path);
                            return report;
                        } catch (IOException exc) {
                            throw new FtpException("Unable to download file " + file.getName(), exc);
                        }
                    })
                    .collect(toList());

                logger.info("Finished downloading reports from SFTP server. Number of reports: {}", reports.size());

                return reports;
            } catch (IOException exc) {
                throw new FtpException("Error while downloading reports", exc);
            }
        });
    }
/**
     * Downloads ALL files from reports directory.
     */
Downloads ALL files from reports directory.
Downloads ALL files from reports directory .
@Dependency(name = FTP_CLIENT, command = FTP_REPORT_DOWNLOADED, type = FTP)
    public List<Report> downloadReports() {
        logger.info("Downloading reports from SFTP server");
        return runWith(sftp -> {
            try {
                SFTPFileTransfer transfer = sftp.getFileTransfer();
                List<Report> reports = sftp.ls(configProperties.getReportsFolder())
                    .stream()
                    .filter(this::isReportFile)
                    .map(file -> {
                        InMemoryDownloadedFile inMemoryFile = new InMemoryDownloadedFile();
                        try {
                            transfer.download(file.getPath(), inMemoryFile);
                            Report report = new Report(file.getPath(), inMemoryFile.getBytes());
                            logger.info("Downloaded report file '{}'", report.path);
                            return report;
                        } catch (IOException exc) {
                            throw new FtpException("Unable to download file " + file.getName(), exc);
                        }
                    })
                    .collect(toList());
                logger.info("Finished downloading reports from SFTP server. Number of reports: {}", reports.size());
                return reports;
            } catch (IOException exc) {
                throw new FtpException("Error while downloading reports", exc);
            }
        });
    }
@ Dependency ( name = FTP_CLIENT , command = FTP_REPORT_DOWNLOADED , type = FTP ) public List < Report > downloadReports ( ) { logger . info ( "Downloading reports from SFTP server" ) ; return runWith ( sftp -> { try { SFTPFileTransfer transfer = sftp . getFileTransfer ( ) ; List < Report > reports = sftp . ls ( configProperties . getReportsFolder ( ) ) . stream ( ) . filter ( this :: isReportFile ) . map ( file -> { InMemoryDownloadedFile inMemoryFile = new InMemoryDownloadedFile ( ) ; try { transfer . download ( file . getPath ( ) , inMemoryFile ) ; Report report = new Report ( file . getPath ( ) , inMemoryFile . getBytes ( ) ) ; logger . info ( "Downloaded report file '{}'" , report . path ) ; return report ; } catch ( IOException exc ) { throw new FtpException ( "Unable to download file " + file . getName ( ) , exc ) ; } } ) . collect ( toList ( ) ) ; logger . info ( "Finished downloading reports from SFTP server. Number of reports: {}" , reports . size ( ) ) ; return reports ; } catch ( IOException exc ) { throw new FtpException ( "Error while downloading reports" , exc ) ; } } ) ; }
Downloads ALL files from reports directory.
Downloads ALL files from reports directory .