Why does Mule FTP connector doesn't delete fil

2019-03-01 03:29发布

问题:

This is the relevant part of my mule-config

<ftp:connector name="ftp.connector" streaming="true"/>

<flow name="ftp2file">
        <ftp:inbound-endpoint connector-ref="ftp.connector" host="xxx" port="21" path="/path" user="test" password="test"/>
        <file:outbound-endpoint path="/newPath" outputPattern="#[header:originalFilename]"/>
    </flow>

Files on FTP server gets deleted when streaming is disabled but files stays on in my case when streaming is enabled.

I've 2 questions:

  1. Why is behavior internally different for streaming versus non streaming
  2. How can I delete files on FTP server in my case

回答1:

As you've seen in https://stackoverflow.com/a/17974787/387927, the answer to Q1 is: because a transfer is still running, as the transport is in streaming mode, Mule will not issue a delete.

The answer Q2 would be to get a hold of the FtpConnector via the registry, get an FTPClient instance with getFtp(uri) using the URI of your FTP endpoint then call deleteFile on the FTPClient.