问题:写了一个Camel的FTP传输程序,在本地Win7和Ubuntu下运行都正常,但是在Redhat中报“File operation failed: 150 Here comes the directory listing”异常
解决方法:
首先贴出修改前的代码以及错误,如下:
代码:
<?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:context="http://www.springframework.org/schema/context" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:META-INF/spring/FtpTransport.properties</value> <value>file:etc/FtpTransport.cfg</value> </list> </property> <property name="ignoreResourceNotFound" value="true"/> </bean> <camel:camelContext id="FtpTransport" streamCache="false" trace="false"> <camel:package>com.angusyang.ftpTransport</camel:package> <camel:route id="ftpTransport"> <camel:from uri="{{source.fullUri}}?username={{source.ftpUser}}&password={{source.ftpPassword}} &delete=false &binary=true &move=done &readLock=changed &useFixedDelay=true &stepwise=false &delay={{transport.fixedDelay}} &antInclude=**/*.xml "/> <camel:log message="got file ${file:name}"/> <camel:marshal> <camel:zipFile/> </camel:marshal> <camel:setHeader headerName="CamelFileName"> <camel:simple>${file:name.noext}.zip</camel:simple> </camel:setHeader> <camel:to uri="{{target.fullUri}}?username={{target.sftpUser}}&password={{target.sftpPassword}}&doneFileName=$simple{file:name.noext}.ack"/> </camel:route> </camel:camelContext> </beans>
在RedHat系统下的错误:
2017-05-11 05:14:41,610 [53.1.114/GL/TM1] WARN FtpConsumer - Consumer FtpConsumer[ftp://127.0.0.1/GL/TM1?antInclude=**%2F*.xml&binary=true&delay=10000&delete=false&move=done&password=xxxxxx&readLock=changed&stepwise=false&useFixedDelay=true&username=angus] failed polling endpoint: Endpoint[ftp://127.0.0.1/GL/TM1?antInclude=**%2F*.xml&binary=true&delay=10000&delete=false&move=done&password=xxxxxx&readLock=changed&stepwise=false&useFixedDelay=true&username=angus]. Will try again at next poll. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - File operation failed: 150 Here comes the directory listing. Accept timed out. Code: 150] org.apache.camel.component.file.GenericFileOperationFailedException: File operation failed: 150 Here comes the directory listing. Accept timed out. Code: 150 at org.apache.camel.component.file.remote.FtpOperations.listFiles(FtpOperations.java:821) at org.apache.camel.component.file.remote.FtpConsumer.doPollDirectory(FtpConsumer.java:122) at org.apache.camel.component.file.remote.FtpConsumer.pollDirectory(FtpConsumer.java:82) at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:131) at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175) at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.net.SocketTimeoutException: Accept timed out at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:404) at java.net.ServerSocket.implAccept(ServerSocket.java:545) at java.net.ServerSocket.accept(ServerSocket.java:513) at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:832) at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:759) at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3293) at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930) at org.apache.camel.component.file.remote.FtpOperations.listFiles(FtpOperations.java:814)
解决方法是,在代码中增加参数“passiveMode=true”就可以了,修改后如下:
<?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:context="http://www.springframework.org/schema/context" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:META-INF/spring/FtpTransport.properties</value> <value>file:etc/FtpTransport.cfg</value> </list> </property> <property name="ignoreResourceNotFound" value="true"/> </bean> <camel:camelContext id="FtpTransport" streamCache="false" trace="false"> <camel:package>com.angusyang.ftpTransport</camel:package> <camel:route id="ftpTransport"> <camel:from uri="{{source.fullUri}}?username={{source.ftpUser}}&password={{source.ftpPassword}} &delete=false &binary=true &move=done &readLock=changed &useFixedDelay=true &stepwise=false &passiveMode=true &delay={{transport.fixedDelay}} &antInclude=**/*.xml "/> <camel:log message="got file ${file:name}"/> <camel:marshal> <camel:zipFile/> </camel:marshal> <camel:setHeader headerName="CamelFileName"> <camel:simple>${file:name.noext}.zip</camel:simple> </camel:setHeader> <camel:to uri="{{target.fullUri}}?username={{target.sftpUser}}&password={{target.sftpPassword}}&doneFileName=$simple{file:name.noext}.ack"/> </camel:route> </camel:camelContext> </beans>