SFTPPlus Documentation

Start Page 4. Configuration Instructions 4.5. Matching expressions

4.5. Matching expressions

Globbing expression or regular expression can be used to select or exclude file names in the SFTPPlus configuration.

4.5.1. Globbing

Globbing expressions provide a simple method for selecting values. It is not suitable for excluding based on a certain pattern.

When globbing expressions are used, the values are matched using case-insensitive matching.

Valid globbing wildcards characters:

  • * - matches everything
  • ? - matches any single character
  • [seq] - matches any character in seq
  • [!seq] - matches any character not in seq

To match a meta-character, please wrap it in brackets. For example, [?] matches the character ?.

To only match PDF files, use the following configuration:

source_filter = *.pdf

4.5.2. Regular Expression

Regular expressions are case-sensitive by default. They can be configured to perform case-insensitive matching.

To instruct the matching to be done using regular expressions, the configured expression needs to be marked as m/EXPRESSION/.

Enclosing the regular expressions inside the m/EXPRESSION/ marker will ensure that leading and trailing blank spaces are not ignored, and are clearly identified when a person reads the configuration.

To perform a case-insensitive matching, enclose the regular expression inside the m/EXPRESSION/i marker. Note the trailing i, which triggers the case-insensitive behaviour.

Regular expression syntax is implemented using the Python RE module, which is modeled after the Perl implementation.

You can test the expression online using the Python section of RegexPlanet.com (leave out the leading *m/* and trailing */* markers).

For example, to only match PDF files whose file names extensions are either *.pdf* or *.PDF* , use the following configuration:

source_filter = m/.*\.pDf/i

In the case that you want to transfer only PDF files whose file name extensions are strictly *.pdf* , use the following configuration:

source_filter = m/.*\.pdf/

To exclude all files with the .pdf extension you can use the leading e/ marker to negate the define expression. This avoids using the regex look-around zero-length assertion rules:

source_filter = e/.*\.pdf/

The regular expression matching, including the exclude matching, are executed as a search function. That is, they will match any part of the targeted value. When you want to do an example match, used the regex anchors for start of line and end of line.

For example, to match only values like report-1.pdf or report-2.pdf and don’t match values like previous-report-1.pdf use the anchors to explicitly instruct an exact match from start to end, like so:

source_filter = m/^report-\d\.pdf$/