简体   繁体   中英

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 . 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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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