1

如何使用 Spring 集成 Sftp Streaming 写入远程文件。我使用 xml 获得了一些代码,但我必须严格使用 java 配置,但我找不到任何。在某些验证失败后,我必须继续将一些数据附加到文件中。所以它不是一次性写入/传输,但我必须保持与远程的连接并继续使用错误日志附加文件。感谢任何帮助。

4

1 回答 1

2

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;
});

写入输出流(从另一个线程)将通过管道传输到输入流。当流关闭时,传输将结束。

于 2016-09-22T13:10:23.703 回答