使用Spring Integrations Sftp Streaming Java配置写入远程文件 [英] Writing to a remote file using Spring Integrations Sftp Streaming java configuration
问题描述
如何使用Spring集成Sftp Streaming写入远程文件.我使用xml获得了一些代码,但是我必须严格使用java配置,但找不到任何.验证失败后,我必须继续向文件中添加一些数据.因此,这不是一次写入/传输,但是我必须保持与远程服务器的连接,并继续向文件中添加错误日志.任何帮助表示赞赏.>
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.
推荐答案
使用SftpRemoteFileTemplate
execute()
和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.
这篇关于使用Spring Integrations Sftp Streaming Java配置写入远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!