I need to save the newly created DomSource object as new xml file into a folder inside the SFTP Server (not transfering a file from local computer into SFTP).
Here is the code
public void save(String xmlFilePath, Document document) {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
Transformer transformer;
try {
transformer = transformerFactory.newTransformer();
DOMSource domSource = new DOMSource(document);
StreamResult streamResult = new StreamResult(new File(xmlFilePath));
transformer.transform(domSource,streamResult);
} catch (TransformerException | NullPointerException e) {
e.printStackTrace();
}
}
CodePudding user response:
Afaik, it's the lost widely used SFTP library for Java
It supports uploading data from streams.
I assume that its
ChannelSftp.put
overload that returnsOutputStream
can be hooked to yourStreamResult
(instead of theFile
).StreamResult streamResult = new StreamResult(channelSftp.put("/sftp/path/file.zml"));