Spring integration FTPs Unable to list files

197 views Asked by At

I have a problem on a spring boot project

I need to retrieve files periodically on a FTPs but spring can't list the files

I have followed the updated documentation (https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html)

I made a java configuration

    @Bean
    public DefaultFtpsSessionFactory sf() {
        DefaultFtpsSessionFactory sf = new DefaultFtpsSessionFactory();
        sf.setHost(this.host);
        sf.setPort(this.port);
        sf.setFileType(FTP.ASCII_FILE_TYPE);
        sf.setUseClientMode(true);
        sf.setProtocol("SSL");
        sf.setUsername(this.username);
        sf.setPassword(this.password);
        sf.setNeedClientAuth(true);
        sf.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
        return sf;
    }

(I tried SSL shared with the same result)

and a periodic reading

  @Bean
    public IntegrationFlow ftpInboundFlow(DefaultFtpsSessionFactory sf) {

        return IntegrationFlows
                .from(Ftp.inboundAdapter(sf)
                                .preserveTimestamp(true)
                                .remoteDirectory("foo")
                                .maxFetchSize(1)
                                .regexFilter(".*\\.txt$")
                        .autoCreateLocalDirectory(true)
                                .localFilename(f -> f.toUpperCase() + ".a")
                                .localDirectory(new File("C:\\\\var\\ftp")),
                        e -> e.id("ftpInboundAdapter")
                                .autoStartup(true)
                                .poller(Pollers.fixedDelay(10000)))
                .handle(m -> System.out.println(m.getPayload()))
                .get();
    }

I have as error:

2022-11-21 12:43:56.018 ERROR 33448 --- [   scheduling-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessagingException: Problem occurred while synchronizing 'foo' to local directory; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:348)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.doReceive(AbstractInboundFileSynchronizingMessageSource.java:267)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.doReceive(AbstractInboundFileSynchronizingMessageSource.java:69)
    at org.springframework.integration.endpoint.AbstractFetchLimitingMessageSource.doReceive(AbstractFetchLimitingMessageSource.java:47)
    at org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:142)
    at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:212)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:444)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:413)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$createPoller$4(AbstractPollingEndpoint.java:348)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda$execute$0(ErrorHandlingTaskExecutor.java:57)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:55)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$createPoller$5(AbstractPollingEndpoint.java:341)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:95)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:317)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:461)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:341)
    ... 21 more
Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
    at org.apache.commons.net.ftp.FTP.getReply(FTP.java:314)
    at org.apache.commons.net.ftp.FTP.getReply(FTP.java:719)
    at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1366)
    at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2270)
    at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2390)
    at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2651)
    at org.springframework.integration.ftp.session.FtpSession.list(FtpSession.java:74)
    at org.springframework.integration.ftp.session.FtpSession.list(FtpSession.java:45)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.transferFilesFromRemoteToLocal(AbstractInboundFileSynchronizer.java:356)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.lambda$synchronizeToLocalDirectory$0(AbstractInboundFileSynchronizer.java:342)
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:452)
    ... 22 more

For your information my ftps works very well with WinSCP

The logs of my local docker for FTPs:

Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [INFO] New connection from 172.19.0.1
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 220-You are user number 1 of 5 allowed.
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 220-Local time is now 11:53. Server port: 21.
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 220-This is a private system - No anonymous login
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 220-IPv6 connections are also welcome on this server.
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 220 You will be disconnected after 15 minutes of inactivity.
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [auth] [TLS]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 234 AUTH TLS OK.
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [INFO] TLS: Enabled TLSv1.3 with TLS_AES_256_GCM_SHA384, 256 secret bits cipher
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [user] [root]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 331 User root OK. Password required
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [pass] [<*>]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [INFO] root is now logged in
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 230 OK. Current directory is /
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [pbsz] [0]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 200 PBSZ=0
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [prot] [P]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 200 Data protection level set to "private"
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [type] [A]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 200 TYPE is now ASCII
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [syst] []
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 215 UNIX Type: L8
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [pasv] []
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 227 Entering Passive Mode (127,0,0,1,117,50)
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] Command [list] [foo]
Nov 21 11:53:33 2d1468cc9968 pure-ftpd: ([email protected]) [DEBUG] 150 Accepted data connection

My docker configuration:


  ftp:
    image: stilliard/pure-ftpd
    restart: always
    tty: true
    stdin_open: true
    environment:
      - FTP_USER_NAME=root
      - FTP_USER_PASS=root
      - FTP_USER_HOME=/home/ftpusers
      - PUBLICHOST=127.0.0.1
      - TLS_USE_DSAPRAM=true
      - ADDED_FLAGS=-d -d --tls=2 
    ports:
      - 21:21
      - 30000-30009:30000-30009
    volumes:
      - type: bind
        source: ./ftp
        target: /home/ftpusers
      - type: bind
        source: ./ssl
        target: /etc/ssl/private

I am in OpenJDK 19.0.1

Thank you in advance for your responses

0

There are 0 answers