Vatsal Mehta
Vatsal Mehta

Reputation: 115

Reading files from SFTP with file name filter on poll basis in mule

I am using groovy script with file name filter to read file from SFTP location on Poll basis using below code

 <poll doc:name="Poll">
            <schedulers:cron-scheduler expression="${payment.schedule}"/>
            <scripting:transformer doc:name="Groovy">
                <scripting:script engine="Groovy">
                    <scripting:text><![CDATA[    
            def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder( 
                    "sftp://${sftp.user}:${sftp.password}@${sftp.host}:${sftp.port}/${sftp.root.path}") 
                    endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter('payment_*'))) 
                    def inboundEndpoint = endpointBuilder.buildInboundEndpoint() 
                    inboundEndpoint.request(3000L) ;
                    ]]></scripting:text>
                </scripting:script>
            </scripting:transformer>
</poll> 

Issue which I am facing here is that, Its reading only one file on each poll schedule. However, my expectation is, it should read all the file which satisfies the condition of filter from SFTP location on each poll schedule.

How can I achieve this? Thanks.

Upvotes: 1

Views: 1922

Answers (1)

Pierre B.
Pierre B.

Reputation: 12943

You may want to use the SFTP Inbound Endpoint with file:filename-wildcard-filter instead of relying on a Groovy script wrapped in a poll. Such as:

<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="payment_*"/> 
</sftp:inbound-endpoint>

See the related example in SFTP documentation.

Upvotes: 1

Related Questions