2017-10-12 121 views

回答

1

您需要使用<int-sftp:outbound-gateway>MGET命令:

消息負載產生從mget操作是List<File>對象 - 一個File對象列表,每個對象表示一個檢索到的文件。

遠程目錄在file_remoteDirectory標題中提供,而在file_remoteFile標題中提供了文件名的模式。

https://docs.spring.io/spring-integration/docs/4.3.12.RELEASE/reference/html/sftp.html#sftp-outbound-gateway

在Java DSL,它看起來像:

.handle(Sftp.outboundGateway(sessionFactory(), AbstractRemoteFileOutboundGateway.Command.MGET, 
         "payload") 
         .options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE) 
         .regexFileNameFilter("(subSftpSource|.*1.txt)") 
         .localDirectoryExpression("'" + getTargetLocalDirectoryName() + "' + #remoteDirectory") 
         .localFilenameExpression("#remoteFileName.replaceFirst('sftpSource', 'localTarget')")) 

其中​​是遠程目錄評估規劃環境地政司表示。在這種情況下,它只是真的請求消息的有效載荷: - 在XML定義expresion="'myRemoteDir'"

String dir = "sftpSource/"; 
registration.getInputChannel().send(new GenericMessage<>(dir + "*")); 

如果你的遠程目錄是靜態的,而不是從批處理改變,你可以使用它作爲LiteralExpression

由於此MGET命令的結果爲List<File>,因此您應該考慮使用Splitter作爲下一步。

+0

嗨@加里,我已經嘗試使用mget命令在[這篇文章] outbound-gateway(https://stackoverflow.com/questions/46707544/how-to-use-sftp-outbound-gateway-mget-command下載文件),我想使用java配置,但我仍然面臨一些問題,我已經閱讀了docs和github的例子,但是我仍然無法解決它,你能不能用java配置給一些mget檢查? TIA –

相關問題