2

我是 Spring 新手,目前正在研究 Spring 与 ftp 支持的集成。

  • 我从本地目录转移到服务器(filZilla)。
  • 我从服务器下载了文件,很好。

但我想知道如何将文件从 FTP 服务器传输到另一个 FTP 服务器,以及是否可以在不从服务器下载文件的情况下读取文件。

4

2 回答 2

1

如果您的意思是获取一个文件并将其发送到另一台服务器而不将其写入本地文件系统,那么,不,目前使用标准组件是不可能的。

但是,您可以使用两个FtpRemoteFileTemplates(使用execute方法)将数据从 an 流式传输InputStream到 an OutputStream

于 2015-03-21T14:46:55.650 回答
0
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)
               }
        }
    }
});
于 2016-07-06T07:56:37.197 回答