spring ftp 使用 'local-filename-generator-expression ' 集成

spring ftp integration using 'local-filename-generator-expression '

我想从 ftp 读取文件并将其存储在本地,与我的根目录下的远程文件的路径相同(我需要它来处理文件)。 远程文件路径是动态的,根据过滤器而变化。 (文件在service-activator调用方法pull时处理)

<int:channel id="ftpChannel">
      <int:queue/>
</int:channel>

    <int-ftp:inbound-channel-adapter id="ftpInbound"
        channel="ftpChannel" session-factory="ftpSessionFactory"
        auto-create-local-directory="true" delete-remote-files="true"
        remote-directory="/"
        remote-file-separator="/" temporary-file-suffix=".writing"
        local-filename-generator-expression ="/+=#this"
        local-directory="${mfg.root.dir}">
        <int:poller fixed-rate="50000" />
    </int-ftp:inbound-channel-adapter>

     <bean id= "directoryFilter" class="il.co.mit.mfg.filter.FilterClass" scope="prototype" >
        <property name="channelType" value="****"/>
        <property name="rootFolder" value="${mfg.root.dir}"/>
    </bean>

    <int:channel id="pubSubChannel">
       <int:queue/>
   </int:channel>
    <int:channel id="output">
      <int:queue/>
     </int:channel>

    <file:inbound-channel-adapter id="inboundfolder"
        channel="pubSubChannel"
        directory="${mfg.root.dir}"
        prevent-duplicates="false">
    </file:inbound-channel-adapter>

    <int:poller default="true" fixed-delay="5000">
          <int:transactional transaction-manager="transactionManager"  />
    </int:poller>

    <int:service-activator id="inputFileServiceActivator"
        input-channel="pubSubChannel" method="pull" ref="typeAdapter" output-channel="output">
</int:service-activator>

    <bean id="ftpSessionFactory"
        class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="*****" />
        <property name="port" value="21" />
        <property name="username" value="******" />
        <property name="password" value="******" />
        <property name="clientMode" value="0" />
        <property name="fileType" value="2" />
        <property name="bufferSize" value="100000" />
    </bean>

我一直在尝试使用 local-filename-generator-expression 但我不确定如何编写 SpEL 表达式。 我对此有点陌生,请帮忙

不清楚你的意思

The remote file path is dynamic and changes according to the filter.

远程路径是文字;过滤器无法更改它。

remote-directory="/"

如果您只是想使用远程文件名作为本地文件名 - 这将是默认设置 - 只需省略 local-filename-generator-expression.

如果您真的想要动态路径而不是文件名,那么使用 ftp outbound gateway 会更好;在那里你可以完全控制远程和本地路径。