read file from SFTP and dump to local folder using mulesoft

孤人 提交于 2019-12-12 03:35:18

问题


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:


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.



来源:https://stackoverflow.com/questions/43092203/read-file-from-sftp-and-dump-to-local-folder-using-mulesoft

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!