简体   繁体   中英

Upload a file to an SFTP server using PDFBox save method without storing the file to the local system?

I'm trying to save the edited PDF which I fetched from the remote server back to its location without having it downloaded/stored on the local machine. I'm using JSch SFTP method to get the input PDF file from the SFTP server using

x = new BufferedInputStream(channelSftp.get("example.pdf"));
PDDocument document = PDDocument.load(x);

and after doing some edits using PDFbox, I'm trying to save it using:

documents.save(new File("ftp/path/location"));

I am not able to because I know it only works for your local directory only. Also I can see that document.save accept OutputStream` parameter, but I do not know how to use it here.

I don't have any problems with taking input using stream reader. All I need is to save that edited PDF back to its location (possibly replace) without having to download it on my local system.

Use the ChannelSftp.put overload that returns OutputStream :

try (OutputStream out = channelSftp.put("example.pdf")) {
    documents.save(out);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM