0

I'm building an API in spring boot and I woudlike to send all files present in my directory (data/all_pdf).

When we detect files in directory, automaticly we send files and delete them when files are successfuly sent.

For example in the all_pdf folder I woudlike to send all files by sftp in another directory and delete all of them from the initiale folder (all_pdf)

@Override
    @ApiOperation("Upload")
    @PostMapping("/upload")
    public boolean uploadFile(String localFilePath, String remoteFilePath) {
        ChannelSftp channelSftp = createChannelSftp();
        String localFilePath = "data/all_pdf";
        String remoteFilePath = "grenn_directory/data/"
        File f= new File(localFilePath);
        File[] listOfFiles = f.listFiles();
        if(listOfFiles.length > 0){
           try {
            channelSftp.put(localFilePath, remoteFilePath);
            return true;
        } catch(SftpException ex) {
            logger.error("Error upload file", ex);
        } finally {
            disconnectChannelSftp(channelSftp);
        }
       }else{

        }

        return false;
    }

EDIT : I don't want to send zip file of all my files but to put each files in sftp

  • What doesnt work? What does this have to do with spring-boot? Clarify your issue. – Deadron Jan 06 '21 at 21:48
  • @Deadron I check if files is present in my directory but when I try to run my post method no files is sending maybe because I not specify the file but the real question is if it's possible with only one `channelSftp.put` requete can I send all files from my directory or I have no choice to do each `channelSftp.put` for each files present. – cryptomania14 Jan 06 '21 at 21:57
  • Just a word of caution: make sure the thing that puts the files in the source directory does so *atomically*. In other words, you don't want to be copying partially written files. The details will probably vary by OS/platform, but might involve writing a file to a temp directory and the moving the file to the watched directory with an atomic operation. – dnault Jan 06 '21 at 22:31
  • @dnault ok thank your for your feedback. We manually drag and drop files to this directory and then we woudlike to push it with this method. So it's impossible to push all files with a single channelSftp.put ? – cryptomania14 Jan 06 '21 at 22:59

0 Answers0