[英]Problems performing on Linux this Spring application that upload a file on an FTP server by Spring Integration FTP: MessagingException
I am pretty new in Spring and I have the following situation. 我在春季非常新,遇到以下情况。
I have implemented a simple console Spring application that perform the upload of a file into an FTP server using Spring Integration FTP project: http://docs.spring.io/spring-integration/reference/html/ftp.html 我已经实现了一个简单的控制台Spring应用程序,该应用程序使用Spring Integration FTP项目将文件上传到FTP服务器: http : //docs.spring.io/spring-integration/reference/html/ftp.html
So I have: 所以我有:
1) MainApp class: 1) MainApp类:
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
MessageChannel ftpChannel = context.getBean("ftpChannel", MessageChannel.class);
File file = new File("C:\\test.txt");
Message<File> fileMessage = MessageBuilder.withPayload(file).build();
ftpChannel.send(fileMessage);
((AbstractApplicationContext) context).close();
}
}
2) And this is the Beans.xml configuration file in which I configure the FTP connection: 2)这是Beans.xml配置文件,在其中配置FTP连接:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-4.2.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd">
<bean id="helloWorld" class="it.myCompany.myProject.batch.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="MY HOST"/>
<property name="username" value="USERNAME"/>
<property name="password" value="PSWD"/>
<property name="clientMode" value="0"/>
<property name="fileType" value="2"/>
<property name="bufferSize" value="10000"/>
</bean>
<int:channel id="ftpChannel"/>
<!--
<int-ftp:outbound-channel-adapter
id="sendFileToServer"
auto-create-directory="true"
session-factory="ftpSessionFactory"
remote-directory="/test"/>
-->
<int-ftp:outbound-channel-adapter id="outFtpAdapter"
channel="ftpChannel"
session-factory="ftpClientFactory"
remote-directory="/home/myFolder"/>
</beans>
From my local Windows machine (performin it from Eclipse) it works fine and the selected file is putted into the /home/myFolder directory on my FTP server. 从我的本地Windows计算机(从Eclipse执行),它可以正常工作,并且所选文件被放到FTP服务器上的/ home / myFolder目录中。
The problem is that I have to perform it as an runnable JAR file on a Linux machine. 问题是我必须在Linux机器上将其作为可运行的JAR文件执行。
So I have simply change this line of the MainApp class: 所以我只需更改MainApp类的这一行:
File file = new File("C:\\test.txt");
in this way: 通过这种方式:
File file = new File("/home/myUser/provaVPC.txt");
(in this way I simply select a specific .txt file into the Linux filesystem). (通过这种方式,我只需在Linux文件系统中选择一个特定的.txt文件)。
And then I exported my project as a runnable JAR file (so it contains all the required dependencies needed to work). 然后,我将项目导出为可运行的JAR文件 (因此它包含工作所需的所有必需依赖项)。
So I put the obtained jar file into the Linux machine but when I try to perform it in this environment I obtain the following error message: 因此,我将获得的jar文件放入Linux机器中,但是当我尝试在这种环境中执行它时,出现以下错误消息:
[maquilanti@jboss_svil ~]$ java -jar TestFtp.jar
Feb 15, 2016 4:25:58 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@490b8a8c: startup date [Mon Feb 15 16:25:58 CET 2016]; root of context hierarchy
Feb 15, 2016 4:25:58 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Feb 15, 2016 4:25:59 PM org.springframework.beans.factory.config.PropertiesFactoryBean loadProperties
INFO: Loading properties file from URL [jar:rsrc:spring-integration-core-4.2.4.RELEASE.jar!/META-INF/spring.integration.default.properties]
Feb 15, 2016 4:25:59 PM org.springframework.integration.config.IntegrationRegistrar registerHeaderChannelRegistry
INFO: No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
Feb 15, 2016 4:26:00 PM org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor registerErrorChannel
INFO: No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
Feb 15, 2016 4:26:00 PM org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor registerTaskScheduler
INFO: No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
Feb 15, 2016 4:26:00 PM org.springframework.beans.factory.config.PropertiesFactoryBean loadProperties
INFO: Loading properties file from URL [jar:rsrc:spring-integration-core-4.2.4.RELEASE.jar!/META-INF/spring.integration.default.properties]
Feb 15, 2016 4:26:00 PM org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler initialize
INFO: Initializing ExecutorService 'taskScheduler'
Feb 15, 2016 4:26:00 PM org.springframework.context.support.DefaultLifecycleProcessor start
INFO: Starting beans in phase 0
Feb 15, 2016 4:26:00 PM org.springframework.integration.endpoint.EventDrivenConsumer logComponentSubscriptionEvent
INFO: Adding {message-handler:outFtpAdapter} as a subscriber to the 'ftpChannel' channel
Feb 15, 2016 4:26:00 PM org.springframework.integration.channel.DirectChannel adjustCounterIfNecessary
INFO: Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@490b8a8c.ftpChannel' has 1 subscriber(s).
Feb 15, 2016 4:26:00 PM org.springframework.integration.endpoint.EventDrivenConsumer start
INFO: started outFtpAdapter
Feb 15, 2016 4:26:00 PM org.springframework.integration.endpoint.EventDrivenConsumer logComponentSubscriptionEvent
INFO: Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
Feb 15, 2016 4:26:00 PM org.springframework.integration.channel.PublishSubscribeChannel adjustCounterIfNecessary
INFO: Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@490b8a8c.errorChannel' has 1 subscriber(s).
Feb 15, 2016 4:26:00 PM org.springframework.integration.endpoint.EventDrivenConsumer start
INFO: started _org.springframework.integration.errorLogger
Your Message : Hello World!
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.springframework.messaging.MessageDeliveryException: Error handling message for file [/home/maquilanti/provaVPC.txt -> provaVPC.txt]; nested exception is org.springframework.messaging.MessagingException: Failed to write to '/home/eds/provaVPC.txt.writing' while uploading the file; nested exception is java.io.IOException: Failed to write to '/home/eds/provaVPC.txt.writing'. Server replied with: 500 Illegal PORT command.
at org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:320)
at org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:282)
at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:410)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:282)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:272)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:264)
at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.handleMessageInternal(FileTransferringMessageHandler.java:142)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at it.hp.miur.batch.MainApp.main(MainApp.java:23)
... 5 more
Caused by: org.springframework.messaging.MessagingException: Failed to write to '/home/eds/provaVPC.txt.writing' while uploading the file; nested exception is java.io.IOException: Failed to write to '/home/eds/provaVPC.txt.writing'. Server replied with: 500 Illegal PORT command.
at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:533)
at org.springframework.integration.file.remote.RemoteFileTemplate.access$500(RemoteFileTemplate.java:59)
at org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:305)
... 19 more
Caused by: java.io.IOException: Failed to write to '/home/eds/provaVPC.txt.writing'. Server replied with: 500 Illegal PORT command.
at org.springframework.integration.ftp.session.FtpSession.write(FtpSession.java:123)
at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:505)
... 21 more
So it seems that, from this Linux environment, it can't send the file because the obtained exception is: 因此,在此Linux环境中,似乎无法发送文件,因为获得的异常是:
Caused by: org.springframework.messaging.MessagingException: Failed to write to '/home/eds/provaVPC.txt.writing' while uploading the file; 由以下原因引起:org.springframework.messaging.MessagingException:上载文件时写入'/home/eds/provaVPC.txt.writing'失败; nested exception is java.io.IOException: Failed to write to '/home/eds/provaVPC.txt.writing'.
嵌套异常为java.io.IOException:无法写入“ /home/eds/provaVPC.txt.writing”。 Server replied with: 500 Illegal PORT command.
服务器回复:500非法PORT命令。
How is it possible if from the Windows environment works fine. 如果从Windows环境运行良好,怎么可能。 I think that the problem is not in the File object creation from a textual file on the file system but it happens when this File object is sended a Message to my FTP server.
我认为问题不在于从文件系统上的文本文件创建File对象,而是在将此File对象发送消息到我的FTP服务器时发生的。 But why?
但为什么? What can be the cause of this problem?
造成此问题的原因是什么? How can I try to solve this issue?
我该如何解决这个问题? What am I missing?
我想念什么?
You need to switch to passive mode, because DefaultFtpSessionFactory use active mode by default. 您需要切换到被动模式,因为DefaultFtpSessionFactory默认情况下使用主动模式。 In your config use clientMode 2
在您的配置中使用clientMode 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.