FTP Session Factory

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

Spring Integration provides factories you can use to create FTP (or FTPS) sessions.

Default Factories

从 3.0 版本开始,默认情况下不再缓存会话。请参阅 FTP Session Caching

Starting with version 3.0, sessions are no longer cached by default. See FTP Session Caching.

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

Before configuring FTP adapters, you must configure an FTP session factory. You can configure the FTP Session Factory with a regular bean definition where the implementation class is o.s.i.ftp.session.DefaultFtpSessionFactory. The following example shows a basic configuration:

<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>

对于 FTPS 连接,您可以改用 o.s.i.ftp.session.DefaultFtpsSessionFactory

For FTPS connections, you can use o.s.i.ftp.session.DefaultFtpsSessionFactory instead.

以下示例显示完整配置:

The following example shows a complete configuration:

<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>

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

If you experience connectivity problems and would like to trace session creation as well as see which sessions are polled, you can enable session tracing by setting the logger to the TRACE level (for example, log4j.category.org.springframework.integration.file=TRACE).

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

Now you need only inject these session factories into your adapters. The protocol (FTP or FTPS) that an adapter uses depends on the type of session factory that has been injected into the adapter.

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

A more practical way to provide values for FTP or FTPS session factories is to use Spring’s property placeholder support (See [role="bare"]https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-placeholderconfigurer).