1. 程式人生 > >Camel FTP error:File operation failed: 150 Here comes the directory listing

Camel FTP error:File operation failed: 150 Here comes the directory listing

found pre one endpoint tpc anti cti dap true

問題:寫了一個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}}&amp;password={{source.ftpPassword}} &amp;delete=false &amp;binary=true &amp;move=done &amp;readLock=changed &amp;useFixedDelay=true &amp;stepwise=false &amp;delay={{transport.fixedDelay}} &amp;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}}&amp;password={{target.sftpPassword}}&amp;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}}&amp;password={{source.ftpPassword}}
                &amp;delete=false
                &amp;binary=true
                &amp;move=done
                &amp;readLock=changed
                &amp;useFixedDelay=true
                &amp;stepwise=false
                &amp;passiveMode=true
                &amp;delay={{transport.fixedDelay}}
                &amp;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}}&amp;password={{target.sftpPassword}}&amp;doneFileName=$simple{file:name.noext}.ack"/>
        </camel:route>
    </camel:camelContext>
</beans>

Camel FTP error:File operation failed: 150 Here comes the directory listing