Nav

To List Files Using the FTP Connector

The List operation returns a List of Messages, where each message represents any file or folder found within the Directory Path (directoryPath).

By default, the operation does not read or list files or folders within any sub-folders of directoryPath.

To list files or folders within any sub-folders, you can set the recursive parameter to true.

This example lists all messages in a directoryPath, without listing the contents of any sub-folders. Note that the path can be absolute, or it can be relative to a Working Directory (workingDir) set in the File configuration (through <ftp:config/>).


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
<flow name="list">
  <ftp:list directoryPath="~/dropFolder" />
  <foreach>
    <choice>
      <when expression="#[attributes.directory]">
        <flow-ref name="processDirectory" />
      </when>
      <otherwise>
        <logger message="Found file #[attributes.path] which content is #[payload]" />
      </otherwise>
    </choice>
  </foreach>
</flow>

The example above lists the contents of a folder, then uses the For Each and Choice components to handle each directory in the list differently than it handles each file.

Matching

You can use the <ftp:matcher> element to filter files based on the matching criteria you use for accepting or rejecting a file. Here is an example of file matching rules you can use:

Example: FTP Matcher

         
      
1
2
3
4
5
6
7
8
9
<ftp:matcher
  filename-pattern="a?*.{htm,html,pdf}"
  path-pattern="a?*.{htm,html,pdf}"
  timestampSince="2015-06-03T13:21:58+00:00"
  timestampUntil="2015-07-03T13:21:58+00:00"
  directory="true|false"
  regularFile="true|false"
  minSize="0"
  maxSize="1024" />

All of the attributes above are optional and are ignored if not provided. They all relate to each other under an AND operator.

As the next examples show, a file matcher can be a reusable element (a named top-level element), or it can be used as an inner element that is proprietary to a particular component.

Example: Top-level, Reusable Matcher


          
       
1
2
3
4
5
6
<ftp:matcher name="smallFileMatcher" maxSize="100" />

<flow name="smallFiles">
  <ftp:list path="smallfiles" matcher="smallFileMatcher" />
  ...
</flow>

Example: Inner, Non-reusable Matcher


          
       
1
2
3
4
5
6
<flow name="smallFiles">
        <ftp:list path="~/smallfiles">
        <ftp:matcher maxSize="100" />
        </ftp:list>
        ...
</flow>

For more on the capabilities of the matcher, see FTP Connector Documentation Reference.

Streaming

The List operation makes use of the repeatable streams functionality introduced in Mule 4. The operation returns a List of Messages, where each message represents a file in the list and holds a stream to the file. That stream is repeatable by default.

For more information on this topic, see About Streaming in Mule 4.0.

In this topic:

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+