FTP 會話工廠
Spring Integration 提供了可用於建立 FTP(或 FTPS)會話的工廠。
預設工廠
從 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>
對於 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>
如果遇到連線問題並希望跟蹤會話建立以及檢視哪些會話被輪詢,可以透過將日誌級別設定為 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)。 |