跳到主要内容
版本:7.0.2

使用 RemoteFileTemplate

DeepSeek V3 中英对照 Using RemoteFileTemplate Using RemoteFileTemplate

Spring Integration 3.0 版本为 SftpSession 对象提供了一个新的抽象层。该模板提供了发送、检索(作为 InputStream)、删除和重命名文件的方法。此外,我们还提供了一个 execute 方法,允许调用者在会话上执行多个操作。在所有情况下,模板都会负责可靠地关闭会话。更多信息,请参阅 RemoteFileTemplate 的 Javadoc。针对 SFTP 有一个子类:SftpRemoteFileTemplate

我们在 4.1 版本中新增了额外的方法,包括 getClientInstance()。该方法提供了对底层 ChannelSftp 的访问,从而能够使用低层级 API。

版本 5.0 引入了 RemoteFileOperations.invoke(OperationsCallback<F, T> action) 方法。该方法允许在同一线程绑定的 Session 范围内调用多个 RemoteFileOperations 操作。当您需要将 RemoteFileTemplate 的多个高级操作作为一个工作单元执行时,这非常有用。例如,AbstractRemoteFileOutboundGatewaymput 命令实现中使用了该方法,其中我们对指定目录中的每个文件及其子目录递归执行 put 操作。更多信息请参阅 Javadoc