Using RemoteFileTemplate
Spring Integration 3.0 版本提供了一个关于 SftpSession
对象的新抽象。该模板提供了一些方法来发送、检索(作为 InputStream
)、删除和重命名文件。此外,我们提供了一个 execute
方法,以便呼叫方在会话中运行多项操作。在所有情况下,该模板都会小心地关闭会话。有关更多信息,请参阅 Javadoc for RemoteFileTemplate
。SFTP 有一个子类: SftpRemoteFileTemplate
。
Spring Integration version 3.0 provides a new abstraction over the SftpSession
object.
The template provides methods to send, retrieve (as an InputStream
), remove, and rename files.
In addition, we provide an execute
method to let the caller run multiple operations on the session.
In all cases, the template takes care of reliably closing the session.
For more information, see the Javadoc for RemoteFileTemplate
There is a subclass for SFTP: SftpRemoteFileTemplate
.
我们在版本 4.1 中添加了更多方法,其中包括 getClientInstance()
。它允许访问基础 ChannelSftp
, 进而访问底层 API。
We added additional methods in version 4.1, including getClientInstance()
.
It provides access to the underlying ChannelSftp
, which enables access to low-level APIs.
5.0 版本引入了 RemoteFileOperations.invoke(OperationsCallback<F, T> action)
方法。该方法让一些 RemoteFileOperations
调用在相同的线程有界 Session
的范围中被调用。当您需要执行 RemoteFileTemplate
的一些高级操作作为一个工作单元时,这会很有用。例如,AbstractRemoteFileOutboundGateway
在 mput
命令实现中使用它,其中我们针对提供的目录中的每个文件执行一个 put
操作,并且针对其子目录递归地执行该操作。有关更多信息,请参阅 Javadoc。
Version 5.0 introduced the RemoteFileOperations.invoke(OperationsCallback<F, T> action)
method.
This method lets several RemoteFileOperations
calls be called in the scope of the same thread-bounded Session
.
This is useful when you need to perform several high-level operations of the RemoteFileTemplate
as one unit of work.
For example, AbstractRemoteFileOutboundGateway
uses it with the mput
command implementation, where we perform a put
operation for each file in the provided directory and recursively for its sub-directories.
See the Javadoc for more information.