spring sftp在没有本地目录的情况下在远程读取和写入

时间:2016-03-11 03:21:18

标签: java spring spring-integration sftp spring-integration-sftp

我知道如何使用spring-integration-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"/>

我尝试删除标记 local-directory 元素但是不允许这样做,有没有办法在不在本地目录中创建文件的情况下读取和写入文件?

有没有办法指定多个不区分大小写的文件扩展名类型?

1 个答案:

答案 0 :(得分:2)

您可以使用带有get选项的出站网关(-stream命令)将远程文件作为InputStream获取。

请注意,一旦从流中读取文件内容,您就有责任关闭会话。

See the documentation here

对于文件入站适配器的不区分大小写的匹配,请使用正则表达式而不是简单模式:filename-regex="(?i).*\.txt"

没有与出站网关匹配的模式;您必须使用ls命令列出文件并获取所需的文件。 sftp sample显示了如何执行此操作。

相关问题