简体   繁体   English

使用Spring Integrations Sftp Streaming Java配置写入远程文件

[英]Writing to a remote file using Spring Integrations Sftp Streaming java configuration

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 . 如何使用Spring集成Sftp Streaming写入远程文件。我使用xml获得了一些代码,但是我必须严格使用java配置,找不到任何。 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. 验证失败后,我必须继续将一些数据追加到文件中。因此,这不是一次写入/传输,但我必须保持与远程的连接并继续使用错误日志追加文件。任何帮助表示赞赏。

Use an SftpRemoteFileTemplate execute() with a SessionCallback ... 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. 流关闭时,传输将结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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