我有一个Web应用程序正在通过spring集成ftp适配器对ftp服务器进行轮询。基本思想是将服务器上的每个新文件提取到本地。它在我的Windows PC上运行得非常完美。一旦在ftp服务器上更新了新文件,适配器就会将其提取到本地目录。但是,当应用程序在Linux服务器上运行时,ftp适配器将停止工作。它在日志中没有给出错误或异常,但是日志文件中缺少来自ftp适配器过滤器的所有调试消息。
以下是applilcationContext.xml
:
<bean id="ftpClientFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="N/A"/>
<property name="username" value="N/A"/>
<property name="password" value="N/A"/>
<property name="port" value="1"/>
</bean>
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel" session-factory="ftpClientFactory"
auto-create-local-directory="true" delete-remote-files="false"
remote-directory="/" local-directory="/tmp/" filter="fileFilter" auto-startup="true">
<int:poller id="poller"
task-executor="pollerPool" max-messages-per-poll="1000" fixedrate="15000"/>
</int-ftp:inbound-channel-adapter>
<task:executor id="pollerPool" pool-size="5" keep-alive="30" queue-capacity="10000" />
文件文件管理器定义为:
public List<FTPFile> filterFiles(FTPFile[] files) {
logger.debug("\nFiltering ftp file...");
List<FTPFile> result = new LinkedList<FTPFile>();
if (localFolder != null) {
for (FTPFile file : files) {
// download files with specific identifier
if (SpreaderFileUtil.checkByIdentifiers(file.getName(), externalIds)) {
// now check whether this file should be download or not
if (SpreaderFileUtil.isDownload(file.getName(), localFolder)) {
result.add(file);
}
}
}
} else {
logger.warn("Local folder is NULL, cannot filter for any files ");
}
return result;
}
我在filer中添加了一个logger用于调试。调试消息显示应用程序在本地PC上运行时,但在服务器上运行时消失。我检查了ftp连接,没关系。在服务器上,我成功构建了一个ftp连接到远程服务器并手动获取文件。我没有任何线索如何继续,因为日志中根本没有错误或异常。任何人都可以帮我解决这个问题吗?提前感谢任何建议。
答案 0 :(得分:4)
好吧,我来关闭这个暂停流。我之前的Spring集成项目中的技巧是客户端模式。以下是参考文档。 http://docs.spring.io/spring-integration/docs/current/api/org/springframework/integration/ftp/session/AbstractFtpSessionFactory.html#setClientMode-int- 事实是,在定义DefaultFtpSessionFactory时,默认客户端模式设置为Active。通过将客户端模式设置为被动模式解决了我的问题。