我知道如何使用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元素,但 Spring 天不允许这样做,有没有办法读取和写入文件而不在本地目录中创建它?
有没有办法指定多个文件扩展名类型而不区分大小写?
1 回答
您可以使用出站网关(带有
-stream
选项的get
命令)将远程文件作为InputStream
获取 .请注意,一旦从流中读取文件内容,您就有责任关闭会话 .
See the documentation here .
对于文件入站适配器上不区分大小写的匹配,请使用正则表达式而不是简单模式:
filename-regex="(?i).*\.txt"
.没有与出站网关匹配的模式;你必须使用
ls
命令列出文件并获取你想要的文件 . sftp sample显示了如何做到这一点 .