0

我知道如何閱讀和SFTP位置與彈簧集成-SFTP下面的配置寫寫:春天SFTP閱讀和遠程的,而不本地目錄

<bean id="sftpSessionFactory" 
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory" 
    p:host="${host}" 
    p:port="${port}" 
    p:user="${username}" 
    p:password="${password}" 
    p:allowUnknownKeys="true" /> 

<int:channel id="sftpChannel"> 
    <int:queue /> 
</int:channel> 

<int-sftp:inbound-channel-adapter 
    id="sftpInboundAdapter" 
    channel="sftpChannel" 
    session-factory="sftpSessionFactory" 
    remote-directory="${remote.dir}" 
    local-directory="${local.dir}"  <-- i don't want 
    auto-create-local-directory="false" 
    delete-remote-files="false" 
    filename-pattern="*.TXT"   <-- how to specify multiple type 
    local-filter="acceptOnceFilter"> 
</int-sftp:inbound-channel-adapter> 

<bean id="acceptOnceFilter" 
    class="org.springframework.integration.file.filters.AcceptOnceFileListFilter"/> 

<int:poller default="true" fixed-rate="1000" max-messages-per-poll="100" /> 

<int:service-activator input-channel="sftpChannel" ref="stringHandler" method="handleMessage"/> 

<bean id="stringHandler" class="com.core.sftp.StringHandler"/> 

我試圖通過移除標籤本地目錄元素,但春天不允許這樣做,有沒有辦法讀取和寫入文件,而不是在本地目錄中創建它?

有沒有辦法指定多個文件擴展名類型,而不區分大小寫?

回答

2

您可以使用出站網關(get命令和-stream選項)將遠程文件作爲InputStream

請注意,一旦您從流中讀取文件內容,您將負責關閉會話。

See the documentation here

對於文件入站適配器不區分大小寫的匹配,請使用正則表達式而不是簡單模式:filename-regex="(?i).*\.txt"

沒有與出站網關匹配的模式;您必須使用ls命令來列出文件並獲取所需的文件。 sftp sample顯示瞭如何做到這一點。

+0

謝謝你加里羅素。是否有任何教程鏈接或示例讀取遠程文件作爲流並將文件寫入遠程InputStream? – Rembo

+0

不是我所知道的;但它很簡單;我提到過的文檔鏈接有一個使用文件分割器從輸入流讀取併發出文本文件的每一行,然後最終關閉會話的示例。這真的取決於你想如何處理數據。 –