无法使用Spring Integration中基于批注的FTPInbound适配器在文件夹之间传输/复制文件

无法使用Spring Integration中基于批注的FTPInbound适配器在文件夹之间传输/复制文件,ftp,spring-integration,Ftp,Spring Integration,我使用以下代码使用FTP入站适配器进行文件传输,但文件不会被传输。这方面的任何线索都会非常有用 @Bean public IntegrationFlow ftpIn() { DefaultFtpSessionFactory defSession=new DefaultFtpSessionFactory(); defSession.setUsername("anonymous"); defSession.setPassword("anonymous!!"); d

我使用以下代码使用FTP入站适配器进行文件传输,但文件不会被传输。这方面的任何线索都会非常有用

@Bean
public IntegrationFlow ftpIn()
{


    DefaultFtpSessionFactory defSession=new DefaultFtpSessionFactory();
    defSession.setUsername("anonymous");
    defSession.setPassword("anonymous!!");
    defSession.setPort(21);
    defSession.setHost("10.47.116.158");


    File localDirectory=new File("C:\\FTP_Default");
    File remoteDirectory=new File("C:\\FilesFromServer");




    return IntegrationFlows.from(Ftp.inboundAdapter(defSession).localDirectory(localDirectory).remoteDirectory("C:\\FilesFromServer")
            .autoCreateLocalDirectory(true),
            e -> e.poller(Pollers.fixedRate(50)).autoStartup(true))
            .channel(this.inputChannel())
            .handle(System.out::println).get();



}
 @Bean
     public DirectChannel inputChannel() {
        return new DirectChannel();
    }

上述问题的解决办法是:

@Bean
public IntegrationFlow ftpIn()
{


    DefaultFtpSessionFactory defSession=new DefaultFtpSessionFactory();
    defSession.setUsername(userId);
    defSession.setPassword(password);
    defSession.setPort(port);
    defSession.setHost(host);
    defSession.setClientMode(2);
    **String remoteDirectory=DefaultFtpSessionFactory.DEFAULT_REMOTE_WORKING_DIRECTORY;**



    File localDirectory=new File("C:\\FilesFromServer");




    return IntegrationFlows.from(Ftp.inboundAdapter(defSession).localDirectory(localDirectory).remoteDirectory(remoteDirectory)
            .autoCreateLocalDirectory(true),
            e -> e.poller(Pollers.fixedRate(50)))
            .channel(this.inputChannel())
            .handle(m -> System.out.println(m.getPayload())).get();


}
 @Bean
     public DirectChannel inputChannel() {
        return new DirectChannel();
    }

上述问题的解决办法是:

@Bean
public IntegrationFlow ftpIn()
{


    DefaultFtpSessionFactory defSession=new DefaultFtpSessionFactory();
    defSession.setUsername(userId);
    defSession.setPassword(password);
    defSession.setPort(port);
    defSession.setHost(host);
    defSession.setClientMode(2);
    **String remoteDirectory=DefaultFtpSessionFactory.DEFAULT_REMOTE_WORKING_DIRECTORY;**



    File localDirectory=new File("C:\\FilesFromServer");




    return IntegrationFlows.from(Ftp.inboundAdapter(defSession).localDirectory(localDirectory).remoteDirectory(remoteDirectory)
            .autoCreateLocalDirectory(true),
            e -> e.poller(Pollers.fixedRate(50)))
            .channel(this.inputChannel())
            .handle(m -> System.out.println(m.getPayload())).get();


}
 @Bean
     public DirectChannel inputChannel() {
        return new DirectChannel();
    }

此外,适配器只能从“localDirectory”读取文件,而不能从理想情况下应该读取的“remoteDirectory”,因为“localDirectory”是文件传输的位置。我有点害怕磁盘上的remoteDirectory C:。你能确认你可以在你的操作系统上使用普通的FTP客户端而不是Spring集成或Java从那里获取文件吗,too@Artem更正此处的“我的本地计算机”作为FTP服务器运行,其中默认服务器文件夹为“C:\\FTP\U默认”我已经将Java类配置为FTP客户端,默认目录为“C:\\FilesFromServer”。是的,我也可以使用简单的FTP客户端或Java来实现相同的功能,但我想使用Spring Integration FTP适配器来实现。我最终发现,为了让适配器检测根服务器目录,我们必须设置会话的这个变量:defaultftpsSessionFactory.DEFAULT_REMOTE_WORKING_directory;它应该工作得很顺利,而且适配器只能从“localDirectory”读取文件,而不能从“remoteDirectory”读取文件,理想情况下应该是这样,因为“localDirectory”是文件传输的地方。我有点害怕磁盘上的remoteDirectory C:。你能确认你可以在你的操作系统上使用普通的FTP客户端而不是Spring集成或Java从那里获取文件吗,too@Artem更正此处的“我的本地计算机”作为FTP服务器运行,其中默认服务器文件夹为“C:\\FTP\U默认”我已经将Java类配置为FTP客户端,默认目录为“C:\\FilesFromServer”。是的,我也可以使用简单的FTP客户端或Java来实现相同的功能,但我想使用Spring Integration FTP适配器来实现。我最终发现,为了让适配器检测根服务器目录,我们必须设置会话的这个变量:defaultftpsSessionFactory.DEFAULT_REMOTE_WORKING_directory;并且它应能顺利工作。变量remoteDirectory必须设置为“DefaultFtpSessionFactory.DEFAULT_REMOTE_WORKING_DIRECTORY”,如上所示,并用于为Ftp填充remoteDirectory。inboundAdapter@Artem就类加载器问题而言,请允许我向您解释一下,我们正在尝试使用SpringBoot将SpringIntegration应用程序代码打包到一个可执行的jar文件中,并在运行时加载它。现在,这可以通过简单的运行时过程实现,然而,我们期望jar中的函数应该返回值,该值将被提供给其他一些代码。这不能通过使用简单的运行时过程实现,因此我们可以调用URIClassLoader方法来实现,在该方法中,我们可以返回一个值以供进一步使用。@Artem请建议您是否看到类似的替代方法变量remoteDirectory必须设置为“DefaultFTPSSessionFactory.DEFAULT_REMOTE_WORKING_DIRECTORY;”,如上所示,并用于填充Ftp的remoteDirectory。inboundAdapter@Artem就类加载器问题而言,请允许我向您解释一下,我们正在尝试使用SpringBoot将SpringIntegration应用程序代码打包到一个可执行的jar文件中,并在运行时加载它。现在,这可以通过简单的运行时过程实现,然而,我们期望jar中的函数应该返回值,该值将提供给其他一些代码。这不能通过使用简单的运行时过程实现,因此我们可以调用URIClassLoader方法来实现,在该方法中,我们可以返回一个值以供进一步使用。@Artem请建议是否有其他方法可供选择