Contact Us 1-800-596-4880

FTP Utils

To test a piece of code that connects with an FTP server, you must install an FTP server in your local environment to run the tests. You could also have a dedicated external FTP server for testing, but your Maven project would not be portable — a third party would need to install the testing FTP server to compile your project.

To make it easier for you to test FTP connections, MUnit allows you to implement an FTP server in your local environment.

Install the MUnit FTP Server Module

  1. From Anypoint Studio, go to the Mule Palette and Search in Exchange…​.

  2. In the search bar, look for MUnit Utils FTP Server and 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 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 anonymous is set to true, you don’t need to set a password to access the FTP server when using the anonymous username.

The default value is true.

secure

(Boolean) Defines the FTP protocol. When the secure parameter is set to true, the server behaves as an SFTP server and connections are allowed only through authentication. If this parameter is set 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 home directory. The default value is the filesystem root.
It is possible to define the FTP user home directory 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 attempts to validate the existence of a file in the FTP server. If the file is not 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 previously.

file

Defines the name of the file to look for.

remove

The remove processor provides another operation that may be of use. This operation 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

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.