2016-01-07 36 views
2

要求:我們正在嘗試實現一個應用程序,其功能是將文件從入站文件夾移動到使用spring sftp出站網關通過sftp處理文件夾。我們已經實現瞭如下所示的sftp出站網關。當我們執行的應用它給什麼,也就是說,既不例外,也不期望輸出(即文件未動過SFTP)如何使用spring集成SFTP網關將文件移動到文件夾?

<int-sftp:outbound-gateway id="remoteftpLS" 
    session-factory="defaultSftpSessionFactory" request-channel="sftpRequestChannel" 
    filename-regex=".*\.txt$" command="mv" expression="'/tmp/datlaa'" 
    rename-expression="'/tmp/datlaa/archive'" /> 

我想從「/ tmp目錄/ datlaa移動* .txt文件到/ tmp/datlaa /存檔。

能否請您在我身邊提出任何配置錯誤。或如何使其工作?

感謝

添加應用程序上下文文件 http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integrationhttp://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/sftphttp://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd「>

回答

1

文件的MV命令處理:

mv命令沒有選項。

expression屬性定義「from」路徑,而rename-expression屬性定義「to」路徑。默認情況下,重命名錶達式是headers ['file_renameTo']。該表達式不能評估爲空或空字符串。如有必要,將創建所需的任何遠程目錄。結果消息的有效負載是Boolean.TRUE。原始遠程目錄在file_remoteDirectory頭中提供,文件名在file_remoteFile頭中提供。新路徑位於file_renameTo標頭中。

請參閱Spring Integration Reference Manual

您的filename-regex被忽略,並且expressionrename-expression都應該指向目標文件。

如果你想處理大量的文件,就像你指定的filename-regex考慮使用SFTP LS Gateway -> Spliter -> SFTP MV Gateway

+0

這不是Spring集成限制,SFTP在重命名命令中不支持通配符。 –

+0

感謝Artem和Gary的迴應。 我們已經通過上述評論,然後嘗試實施實際要求。即從sftp讀取文件,然後通過sftp將相同的文件移動到存檔文件夾。爲此,我們在上下文文件中完成了下面的配置,但仍然沒有移動文件。除了配置文件,我們有一個Java主類,它只加載上下文文件。你可以請建議我們需要改變配置/在Java類中添加任何代碼。 – ragani

+0

Java Class 'public class SftpGatewaySample {0} {0}私有靜態記錄器記錄器= Logger.getLogger(SftpGatewaySample.class); \t公共靜態無效的主要(字串[] args){ \t \t ApplicationContext的上下文= \t \t \t \t新的ClassPathXmlApplicationContext( 「outboundGateway.xml」);」 – ragani

相關問題