read file from SFTP and dump to local folder using

2019-08-27 04:55发布

Can someone provide me an mulesoft xml where the flow is reading files from SFTP location and dumping it to the local directory.

I have written following code but it does not work: subflow :

    <sub-flow name="loadFtpFile">
    <logger message="Load FTP File: #[flowVars.fileName]" level="INFO" doc:name="Load FTP File"/>
    <logger message="#[payload]" level="DEBUG" doc:name="Log Payload"/>
</sub-flow>

And the flow is :

<flow name="readFTP">
     <logger message="Read FTP file" level="INFO" doc:name="Read FTP file"/>
    <set-variable variableName="sftpEndpoint" value="sftp://{someUser}:{password}@{host}:22/incoming/test" doc:name="Set SFTP Endpoint"/>
    <set-variable variableName="fileName" value="debug.log" doc:name="Set File Name"/>
    <flow-ref name="loadFtpFile" doc:name="loadFtpFile"/>
   <file:outbound-endpoint path="C:\Users\Vikas\home\product" responseTimeout="10000" doc:name="Templocation" />

1条回答
叛逆
2楼-- · 2019-08-27 05:09

here is a example from the official documentation.

configuation:

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
      xmlns:file="http://www.mulesoft.org/schema/mule/file"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
          http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
          http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">

    <!-- This placeholder bean lets you import the properties from the sftp.properties file. -->
    <spring:bean id="property-placeholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <spring:property name="location" value="classpath:sftp.properties"/>
    </spring:bean>

    <flow name="sftp2file">
        <sftp:inbound-endpoint host="${sftp.host}" port="${sftp.port}" path="/home/test/sftp-files" user="${sftp.user}" password="${sftp.password}"> 
                    <file:filename-wildcard-filter pattern="*.txt,*.xml"/> 
                </sftp:inbound-endpoint>
        <file:outbound-endpoint path="/tmp/incoming" outputPattern="#[message.inboundProperties.originalFilename]"/> 
    </flow>
</mule>

and here the references properties file:

sftp.user=memyselfandi
sftp.host=localhost
sftp.port=8081
sftp.password=icannottellyou

try it out and feel free to ask more precise queation.

查看更多
登录 后发表回答