Spring Integration未在FTP文件夹中检测到文件。

huangapple go评论52阅读模式
英文:

Spring Integration is not detecting files on FTP Folder

问题

目前我遇到了一个问题,不知道该怎么解决。我正在开发一个简单的应用程序,通过不同的FTP和SFTP服务器传输文件进行处理。起初,这些服务器还没有准备好,所以我在我的计算机上使用Apache Mina和RebexTinySftpServer设置了一个FTP服务器和一个SFTP服务器来测试我的开发。

使用这些应用程序,我在本地完成并测试了我的应用程序,所以现在是时候使用将在生产中使用的服务器进行测试了。但是FTP服务器出了些问题,Spring Integration无法检测到放在文件夹中等待传输到SFTP服务器的文件。

每个服务器上都有两个文件夹:一个用于输入文件,另一个用于输出文件。因此,当Spring Integration检测到SFTP服务器的输入文件夹中有新文件时,它会将文件传输到FTP服务器的输入文件夹,以供另一个服务进行处理。这部分运作正常。

在该服务处理文件后,它会生成一个输出文件并将其存储在FTP服务器的输出文件夹中,以供传输到SFTP服务器的输出文件夹,但是由于某种原因,Spring Integration无法检测到这些文件,并且不会传输其中任何一个。这部分是我不知道如何解决的,因为没有抛出任何异常,所以我不知道需要修改代码的哪个部分。

以下是我定义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;
}

以下是我定义FTP入站适配器的代码:

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

我应该提到FTP服务器正在运行在AS/400系统上,所以这可能与我面临的问题有关。

英文:

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.

答案1

得分: 1

我找到了解决我的问题的方法。我在这里发布,以防类似情况发生在其他人身上。

我的项目使用的是spring-integration-ftp 5.5.16,它有commons-net 3.8.0作为依赖项。出于某种原因,commons-net的那个版本不能检索AS400目录内的文件,所以我排除了spring-integration-ftp中的这个依赖,并在我的项目中添加了commons-net 3.9.0。现在一切都正常工作。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月8日 10:39:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380905.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定