Ahmed
Ahmed

Reputation: 23

Transfer file from ftp Server to another ftp server using spring integration ftp support

I am new to Spring and I am currently working on spring integration with ftp support.

But I want to find how I can Transfer file from FTP Server to another FTP Server and if it's possible to read file without downloading it from the server.

Upvotes: 2

Views: 1295

Answers (2)

steviemo
steviemo

Reputation: 104

FtpRemoteFileTemplate server1;
FtpRemoteFileTemplate server2
server1.get("filetotransfer", new InputStreamCallback() {
    @Override
    public void doWithInputStream(final InputStream stream) throws IOException {
        server2.executeWithClient(new ClientCallback<FTPClient, Void>() {
            @Override
            public Void doWithClient(final FTPClient client) {
               try (final OutputStream outStream = client.storeFileStream("filedestination");) {
                   IOUtils.copyLarge(stream, outputStream)
               }
        }
    }
});

Upvotes: 0

Gary Russell
Gary Russell

Reputation: 174514

If you mean fetch a file and send it to another server without writing it to the local file system then, no, that's not currently possible with standard components.

However, you can use two FtpRemoteFileTemplates (use the execute method) to stream the data from an InputStream to an OutputStream.

Upvotes: 1

Related Questions