Mind Peace
Mind Peace

Reputation: 915

Mule SFTP Component component

I am developing mule flow wherein mule process has to upload file/files (from source directory) to SFTP server.

IN Folder (This folder holds file to transfer to SFTP)

I have below mule flow

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
       xmlns:spring="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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">
    <flow name="sftpFlow1">
        <poll doc:name="Poll">
            <fixed-frequency-scheduler frequency="30" startDelay="10" timeUnit="SECONDS"/>
            <logger message="Hi" level="INFO" doc:name="Logger"/>
        </poll>
        <flow-ref name="sftpSub_Flow" doc:name="Flow Reference"/>
    </flow>
    <sub-flow name="sftpSub_Flow">
        <file:outbound-endpoint path="D:\IN" responseTimeout="10000" doc:name="File"/>
        <sftp:outbound-endpoint exchange-pattern="one-way" host="host" port="port" path="sftppath" user="user" password="password" responseTimeout="10000" doc:name="SFTP"/>
    </sub-flow>

</mule>

Issues: I don't see any error or exceptions but expected files from IN folder are not getting transfer SFTP server. I see ****.dat file every time sub-flow executes.

Any suggestion?

Upvotes: 1

Views: 793

Answers (2)

aled
aled

Reputation: 25802

Because the application doesn't actually show any input, I'll assume that the sample is flawed but the real application has some inbound endpoint (for example a file inbound endpoing) that is reading in streaming mode. The subflow is trying to consume two time the input stream to output to the two outbound endpoints. Because the first one consumes the stream the second one, the SFTP, gets a consumed empty stream as input so it doesn't output anything. A solution is to convert the input to something in memory, like using the object to byte array transformer in the middle. Be warned that for large files you might run out of memory doing this.

Upvotes: 0

Here you have used both outbound end points. You need file inbound end point component to pick the file from source location. refer below sample for further https://dzone.com/articles/anypoint-file-connector-with-mulesoft

you can use the outputPattern property in sftpoutbound endpoint to change the file name with any extension

Upvotes: 1

Related Questions