问题
How to write to a remote file using Spring integrations Sftp Streaming .I got some code using xml but I have to strictly use java configuration and I cant find any . I have to keep on appending some data to the file after some validation failure.So its not a one time write/transfer but I have to maintain the connection with remote and keep on appending the file with error logs.Any help appreciated.
回答1:
Use an SftpRemoteFileTemplate
execute()
with a SessionCallback
...
SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(sessionFactory);
PipedInputStream pipe = new PipedInputStream();
OutputStream outputStream = new PipedOutputStream(pipe);
template.execute(s -> {
s.write(pipe, "/foo/bar.log");
return null;
});
Writing to the output stream (from another thread) will be piped to the input stream. Transfer will end when the stream is closed.
来源:https://stackoverflow.com/questions/39630475/writing-to-a-remote-file-using-spring-integrations-sftp-streaming-java-configura