使用 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 的多個高階操作作為工作單元執行時,這非常有用。例如,AbstractRemoteFileOutboundGateway 將其用於 mput 命令實現,其中我們對所提供目錄中的每個檔案及其子目錄遞迴執行 put 操作。有關更多資訊,請參閱 Javadoc

© . This site is unofficial and not affiliated with VMware.