Contact Us 1-800-596-4880

FTP Utils

logo acb active Anypoint Code Builder

logo studio active Anypoint Studio

To test a piece of code that connects with an FTP server, install an FTP server in your local environment to run the tests. You can also use a dedicated external FTP server for testing, but your Maven project can’t be portable. A third party must install the testing FTP server to compile your project.

To test the FTP connections, you can implement an FTP server in your local environment with MUnit.

Install the MUnit FTP Server Module

To install the MUnit FTP server module:

  1. Look for the MUnit Utils FTP Server module in Exchange.

  2. Add the module to your project:

    <!-- Ftp Server Dependency -->
    <dependency>
        <groupId>com.mulesoft.munit.utils</groupId>
        <artifactId>munit-ftpserver-module</artifactId>
        <version>2.0.1</version>
        <classifier>mule-plugin</classifier>
        <scope>test</scope>
    </dependency>

    The MUnit FTP server artifact in your POM file must have the test scope.

Attributes Reference

The FTP server module takes the following parameters:

Attribute Name Description

name

Defines the configuration name of the FTP server.
This value must be unique.

port

Defines the port on which the FTP server listens.

anonymous

(Boolean) Sets anonymous access to the FTP server. If you set anonymous to true, don’t set a password to access the FTP server when using the anonymous username.
The default value is true.

secure

(Boolean) Defines the FTP protocol. If you set the secure parameter to true, the server behaves as an SFTP server and connections must be authenticated. If you set the secure parameter to false, the server behaves as an FTP server and allows either authenticated or anonymous connections.
The default value is false.

homeDir

Defines the user’s home directory. The default value is the filesystem root.
You can define the FTP user home directory by using the ~ character to represent the home directory on the file system.

MUnit FTP Server Processors

The FTP Utility has two processors to interact with your FTP server:

contains-files

The contains-files processor validates the existence of a file in the FTP server. If there is no file present, the processor fails causing the test to fail.

<ftpserver:contains-files config-ref="MUnit_FTP_Server_Config" path="/" file="example.txt"/>
Attribute Name Description

config-ref

Defines the FTP server configuration.

path

Defines in which folder to search based on the user home directory defined.

file

Defines the name of the file to look for.

remove

The remove processor provides an operation that instructs the FTP server to remove a file from storage.

<ftpserver:remove config-ref="MUnit_FTP_Server_Config" path="example.txt"/>
Attribute Name Description

config-ref

Defines the FTP server configuration.

path

Defines the full path of the file to remove.

This feature is useful when creating the same file name several times. You can configure it in after-test to ensure that no name collisions cause the test to fail.