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