跳到主要内容

FTP 会话工厂

QWen Plus 中英对照 FTP Session Factory

Spring Integration 提供了你可以使用的工厂来创建 FTP(或 FTPS)会话。

默认工厂

important

从 3.0 版开始,会话不再默认缓存。请参阅 FTP 会话缓存

在配置 FTP 适配器之前,您必须配置一个 FTP 会话工厂。您可以使用常规的 bean 定义来配置 FTP 会话工厂,其中实现类是 o.s.i.ftp.session.DefaultFtpSessionFactory。以下示例显示了一个基本配置:

<bean id="ftpClientFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="localhost"/>
<property name="port" value="22"/>
<property name="username" value="kermit"/>
<property name="password" value="frog"/>
<property name="clientMode" value="0"/>
<property name="fileType" value="2"/>
<property name="bufferSize" value="100000"/>
</bean>
xml

对于 FTPS 连接,你可以使用 o.s.i.ftp.session.DefaultFtpsSessionFactory 代替。

以下示例显示了一个完整的配置:

<bean id="ftpClientFactory"
class="org.springframework.integration.ftp.session.DefaultFtpsSessionFactory">
<property name="host" value="localhost"/>
<property name="port" value="22"/>
<property name="username" value="oleg"/>
<property name="password" value="password"/>
<property name="clientMode" value="1"/>
<property name="fileType" value="2"/>
<property name="useClientMode" value="true"/>
<property name="cipherSuites" value="a,b.c"/>
<property name="keyManager" ref="keyManager"/>
<property name="protocol" value="SSL"/>
<property name="trustManager" ref="trustManager"/>
<property name="prot" value="P"/>
<property name="needClientAuth" value="true"/>
<property name="authValue" value="oleg"/>
<property name="sessionCreation" value="true"/>
<property name="protocols" value="SSL, TLS"/>
<property name="implicit" value="true"/>
</bean>
xml
备注

如果您遇到连接问题,并希望跟踪会话创建以及查看哪些会话被轮询,您可以通过将日志记录器设置为 TRACE 级别来启用会话跟踪(例如,log4j.category.org.springframework.integration.file=TRACE)。

现在你只需要将这些会话工厂注入到你的适配器中。适配器使用的协议(FTP 或 FTPS)取决于注入到适配器中的会话工厂的类型。

备注

为 FTP 或 FTPS 会话工厂提供值的一种更实用的方法是使用 Spring 的属性占位符支持(参见 docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-placeholderconfigurer)。