1

Currently I'm facing a problem where I don't know what to do to resolve it. I'm developing a simple application that transfer files through different FTP and SFTP servers to be processed. Well, at the beginnig those servers weren't ready, so I used Apache Mina and RebexTinySftpServer to set a FTP server and a SFTP server on my computer to test my development.

With those applications I completed and tested my application locally, so it was time to test it using the servers that will be used in production, but something is wrong with the FTP server and Spring Integration is not detecting the files that are put in the folder to be transferred to the SFTP server.

I have two folders on each server: one for Input files and the another one for Output files. So when Spring Integration detects that there's a new file in the Input folder on the SFTP Server, it transfers the file to the Input folder on FTP Server to be processed for another service. That part works fine.

After that service processes the file, it generates an output file and stores it in the Output folder on the FTP Server to be transferred to the Output folder on the SFTP server, but for some reason Spring Integration is not detecting those files and doesn't transfer none of them. This part is what I don't know how to solve because none Exception is being thrown, so I don't know what part of my code I have to modify.

Here is my code where I define the DefaultFtpSessionFactory:

public DefaultFtpSessionFactory ftpSessionFactory() {
    DefaultFtpSessionFactory session = new DefaultFtpSessionFactory();
    session.setUsername(username);
    session.setPassword(password);
    session.setPort(port);
    session.setHost(host);
    session.setFileType(FTP.ASCII_FILE_TYPE);
    session.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
    return session;
}

And here is the code where I define the FTP Inbound Adapter:

@Bean
FtpInboundChannelAdapterSpec salidaAS400InboundAdapter() {
    return Ftp.inboundAdapter(as400Session.ftpSessionFactory())
            .preserveTimestamp(true)
            .remoteDirectory(as400Session.getPathSalida())
            .deleteRemoteFiles(true)
            .localDirectory(new File("tmp/as400/salida"))
            .temporaryFileSuffix(".tmp");
}

I should mention that the FTP Server is running on an AS/400 system, so maybe that has something to do with the situation I'm facing.

jmartinez
  • 71
  • 1
  • 5
  • Consider to configure a DEBUG logging level for `org.springframework.integration` category to observer some events when your `Ftp.inboundAdapter` is in action. There may be a log like `Cannot rename`. – Artem Bilan Feb 08 '23 at 14:33
  • Hi @ArtemBilan, thanks for replying. I did what you suggested and the only log that I see with DEBUG level are the next: `Connected to server [xxx.xxx.xxx.xxx:xx]`, `0 files transferred from '/H2H/Salida/'`, and `Received no Message during the poll, returning 'false'`. – jmartinez Feb 08 '23 at 14:57
  • OK. At least we see now that no files are transferred. Can you debug your solution and place a break point in the `AbstractInboundFileSynchronizer.transferFilesFromRemoteToLocal` to see what `session.list(remoteDirectory)` returns for you? – Artem Bilan Feb 08 '23 at 15:14
  • `session.list(remoteDirectory)` returns an empty array, so the `AbstractInboundFileSynchronizer.transferFilesFromRemoteToLocal` function returns 0. – jmartinez Feb 08 '23 at 15:44
  • Then there is nothing what we can do from our side: turns out your FTP client cannot see entries in that `/H2H/Salida/` remote dir. – Artem Bilan Feb 08 '23 at 16:03
  • I see. Do you think there is some kind of specific configuration that should be set on the FTP server to Spring Integration be able to retrieve the directory's entries? When I use Apache Mina locally, it works perfecty, but I use the default configuration, so I don't know if there's something configured differently on the AS400. – jmartinez Feb 08 '23 at 17:02
  • Neither do I: never worked with AS400. Since we got an answer from `FtpSession.list()`, then connection happens properly. Therefore something else is needed to be done on the server side to make the files in that dir to be visible for FTP client. – Artem Bilan Feb 08 '23 at 17:05
  • I see. Then I'll talk to the AS400 team to check the FTP server configuration and maybe find something. Thanks again for trying to help. – jmartinez Feb 08 '23 at 17:10
  • 1
    Hi @ArtemBilan, I found the solution. It wasn't something bad in the FTP Server, but a dependency in `spring-integration-ftp`. My project is using `spring-integration-ftp 5.5.16` that has `commons-net 3.8.0` as a dependency. For some reason, that version of `commons-net` was retrieving the empty array, so I exclude that dependecy from `spring-integration-ftp` and included version 3.9.0 in my project and it works now. I don't know if it's some kind of bug in version 3.8.0 inside `spring-integration-ftp`, but version 3.9.0 solved my problem. – jmartinez Feb 08 '23 at 19:50

1 Answers1

1

I found the solution of my problem. I'm posting this in case something similar happens to someone else.

My project is using spring-integration-ftp 5.5.16 that has commons-net 3.8.0 as a dependency. For some reason, that version of commons-net wasn't retrieving the files inside the directory of the AS400, so I excluded that dependency from spring-integration-ftp and added commons-net 3.9.0 in my project. Now everything works fine.

jmartinez
  • 71
  • 1
  • 5
  • Good to know! Unfortunately we cannot upgrade that `5.5.x` version to newer `commons-net` since the rule is not to pull minor version to point version. We will upgrade to a that one in the next `6.1`. – Artem Bilan Feb 08 '23 at 20:17