简体   繁体   English

使用Spring-Integration下载FTP文件?

[英]FTP file download with Spring-Integration?

I want to download a file from ftp server periodically (only when the file has changed). 我想定期从ftp服务器下载文件(仅当文件发生变化时)。 Therefore I'd like to use Spring-Integration 4.0. 因此,我想使用Spring-Integration 4.0。

What is the annotation based configuration equivalent of the following setup with int-ftp ? 什么是基于注释的配置等效于使用int-ftp的以下设置?

<int-ftp:inbound-channel-adapter id="ftpInbound"
            channel="ftpChannel"
            session-factory="ftpClientFactory"
            filename-pattern="*.txt"
            auto-create-local-directory="true"
            delete-remote-files="false"
            remote-directory="/">
    <int:poller fixed-rate="1000"/>
</int-ftp:inbound-channel-adapter>

I started with the following, but don't know how I can configure the channel with its attributes like session-factory , remote-directory etc. 我从以下开始,但不知道如何使用session-factoryremote-directory等属性配置通道。

@Configuration
@EnableIntegration
public class Application {
    @Bean
    public SessionFactory<FTPFile> sessionFactory() {
        DefaultFtpSessionFactory ftp = new DefaultFtpSessionFactory();
        ftp.setHost("ftp.test");
        ftp.setPort(21);
        ftp.setUsername("anonymous");
        ftp.setPassword("anonymous");
        return ftp;
    }

    @InboundChannelAdapter(value = "ftpChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
    public String connect() {
        // return the ftp file
    }

    @ServiceActivator(inputChannel = "ftpChannel")
    public void foo(String payload) {
        System.out.println("paylod: " + payload);
    }

}

The (S)FTP inbound adapters are on the more complex side; (S)FTP入站适配器位于更复杂的一侧; we're working in the DSL to make this easier but, currently, you need an @Bean FtpInboundFileSynchronizer wired up with appropriate properties and inject it into 我们正在DSL中工作以使这更容易,但是,目前,你需要一个@Bean FtpInboundFileSynchronizer连接适当的属性并将其注入

Then 然后

@Bean
@InboundChannelAdapter(value = "ftpChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource receive() {
    FtpInboundFileSynchronizingMessageSource messageSource = new FtpInboundFileSynchronizingMessageSource(synchronizer());
    ...
    return messageSource;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM