> For the complete documentation index, see [llms.txt](https://docs.getmesa.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getmesa.com/tools/ftp.md).

# FTP

The **FTP (File Transfer Protocol)** tool allows you to download and upload files to a specified FTP server. With MESA, you can map the data to a format that Shopify or another system expects and pass it along to the next step. Sharing CSV and other files via FTP servers is a great choice to connect your fulfillment service, product manager, or another third-party system to Shopify. MESA supports both FTP and SFTP (secure FTP) protocols.

{% hint style="info" %}
**Please note**: At this time, MESA does not support SSH keys for FTP.
{% endhint %}

## Connection <a href="#connect" id="connect"></a>

Your hosting service should have details for all fields required to [connect your FTP with MESA](/going-further/credentials.md).

<figure><img src="/files/RmtZGzowQ7TWaZT8MwNj" alt="Screenshot of the MESA FTP connection form, filled with the FTP server host, username, and password credential fields. Spotlight the Add Connection button."><figcaption></figcaption></figure>

Once all the details have been filled in, click **Add Connection** to connect your FTP with MESA.

## Configuration <a href="#configuring" id="configuring"></a>

### Fetch File triggers <a href="#triggers" id="triggers"></a>

You can begin a workflow by fetching a FTP, XML, or CSV file on a scheduled basis.

<figure><img src="/files/XKzERVAeRIUJfH19E5U9" alt="Screenshot of the MESA workflow builder trigger picker for the FTP tool, showing the Fetch FTP, XML, and CSV file triggers that run on a schedule. Spotlight the Fetch File trigger options."><figcaption></figcaption></figure>

Once you have selected your preferred FTP trigger, there are fields available to complete:

* [File Name](#file-name)
* [Move File After Successful Read](#move-file)
* [Scheduled Time](#scheduled-time)

### **File Name**

Enter the path to the file on your FTP server.

<figure><img src="/files/pxKPsPwPBYPaYyYO2USw" alt="Screenshot of the MESA FTP Fetch File trigger configuration with the path to the file on the FTP server entered. Spotlight the File Name field."><figcaption></figcaption></figure>

To check if you have correctly entered your path, you can click on the Retrieve File button to test.

<figure><img src="/files/f15RLUIHYricmMY4Syxz" alt="Screenshot of the MESA FTP Fetch File trigger configuration used to test the entered file path. Spotlight the Retrieve File button."><figcaption></figcaption></figure>

If MESA cannot locate your file, an error will display, stating that the file is not found or could not be read. To fix this, please adjust the text entered into the File Name field.

<figure><img src="/files/JwYyp043x5ew46hD7o2A" alt="Screenshot of the MESA FTP Fetch File trigger after clicking Retrieve File with an invalid path, showing the file not found error. Spotlight the file not found or could not be read error message."><figcaption></figcaption></figure>

Optionally, you can use wildcards (\*) to match portions of the path if the path is dynamic. If you are familiar with regular expressions, you can test the wildcard placement on a third-party website (e.g. [regex101](https://regex101.com/)) to ensure that the pattern matches the file path.

<figure><img src="/files/szSZsp4FWnePrQrrdaq6" alt="Screenshot of the MESA FTP Fetch File trigger with a wildcard character used in the file path to match a dynamic portion of the path. Spotlight the File Name field wildcard."><figcaption></figcaption></figure>

<figure><img src="/files/emomEDMDYsldxFQcYmb3" alt="Screenshot of the regex101 website used to test a wildcard pattern against an FTP file path. Spotlight the regular expression and test string match."><figcaption></figcaption></figure>

### **Move File After Successful Read**

If selected, the file will be moved after MESA successfully reads it. This is useful if you have a dedicated directory/folder to store read files so your FTP server is organized. This can be found by selecting the [More fields](https://docs.getmesa.com/workflow-builder/fields#additional-fields) button.

<figure><img src="/files/ykQLhM6OFbetG5sCH9Ih" alt="Screenshot of the MESA FTP Fetch File trigger with the More fields section expanded to reveal the Move File After Successful Read option. Spotlight the Move File After Successful Read setting."><figcaption></figcaption></figure>

In the below screenshot, the "processed" folder stores all files that have been read.

![Screenshot of the FTP server file directory showing a processed folder that stores all files MESA has read. Spotlight the processed folder.](/files/CeQPOEtDGrQwrerVcsAU)

For the Moved File Name field, you can use the [Variable](/workflow-builder/fields/variables.md) {{file}} which is from the file name. For example, if the file name value is **orders/Order\*.csv**, and the found file was **orders/Order-1234.csv**, {{file}} would resolve to **Order-1234.csv**.

For our example, we have inputted: processed/orders/{{file}}

<figure><img src="/files/tDV1SPj0g2s7I2D9FZeh" alt="Screenshot of the MESA FTP Fetch File trigger Move File After Successful Read option with processed/orders/{{file}} entered. Spotlight the Moved File Name field."><figcaption></figcaption></figure>

### **Scheduled Time**

Towards the bottom of the configuration, you can configure how often you'd like your workflow to run. Make sure to click the Save button to save your changes.

<figure><img src="/files/Y0qOVt4JBmvmqVQtIBiT" alt="Screenshot of the MESA FTP Fetch File trigger scheduling section at the bottom of the configuration, used to set how often the workflow runs. Spotlight the Scheduled Time and Save button."><figcaption></figcaption></figure>

## Going Further <a href="#save-ftp-action" id="save-ftp-action"></a>

### Save FTP File action <a href="#save-ftp-action" id="save-ftp-action"></a>

* [Advanced Data Mapping](#advanced-data-mapping)

In the File Name field, you can input your preferred name of the file that will be sent to your FTP server.

<figure><img src="/files/qLajBzvHtcHIfXGObYoh" alt="Screenshot of the MESA Save FTP File action configuration with the preferred output file name entered. Spotlight the File Name field."><figcaption></figcaption></figure>

Example: **products/all-products-{{ "now" | date: "\_%m\_%d\_%Y\_%I\_%M\_%S\_%p" }}.csv** will create a file in the products folder, with the name **all-products-\_07\_12\_2024\_09\_48\_54\_AM.csv**

[Learn more about formatting dates with Liquid](/workflow-builder/fields/liquid-templating.md#date).

In the **Data Mapping** section, you can map out the data sent to your FTP server by utilizing [MESA's Variables feature](/workflow-builder/fields/variables.md).

<figure><img src="/files/8zXzomSezeGdsHDIPLgq" alt="Screenshot of the MESA Save FTP File action showing the Data Mapping section where the data sent to the FTP server is mapped using Variables. Spotlight the Data Mapping section."><figcaption></figcaption></figure>

**Advanced Data Mapping**

For more advanced mapping, you can also use the **Edit Code** button on the FTP action, then add in your own data mapping.

<figure><img src="/files/27ukRWR4RexR3ae4wCBc" alt="Screenshot of the MESA Save FTP File action with the code editor open for advanced data mapping. Spotlight the Edit Code button."><figcaption></figcaption></figure>

The following code will take a list of Shopify products, and create CSV file content from them. The **Mesa.csv.encode()** method is used to convert the data into CSV format. See the MESA Script SDK [documentation](https://docs.getmesa.com/tools/custom-code/sdk#vendor-mesa.js-mesa.csv.encode) for more details.

```javascript
script = (payload, context) => {
  // Adjust `payload` here to alter data before we transform it.

  // Alter the payload data based on our transform rules
  let csvRows = [];

  payload.forEach((product) => {
    csvRows.push({
      id: product.id,
      title: product.title,
      handle: product.handle,
      status: product.status,
    });
  });

  // Adjust `output` here to alter data after we transform it.
  const csvOutput = Mesa.csv.encode(csvRows, true);

  // We're done, call the next step!
  Mesa.output.next(csvOutput);
};
```

## Technical Notes

#### Fetch CSV File Row Created Trigger

* This trigger can support a CSV file with over 10,000 rows.
* Our queue will batch 50 rows at a time. After those 50 rows are processed, the next 50 will be enqueued. This continues until all rows have been processed.
* We do not recommend parallel processing for this trigger as it can disrupt the enqueuing logic.
* For CSV files with more than 1,000 rows, avoid using short schedule intervals as this may conflict with existing runs. For files over 1,000 rows, set the schedule to approximately 1 hour. For files with 10,000+ rows, keep schedule times several hours apart to prevent double booking
* Unlike other triggers that support enqueueing multiple files, this trigger only enqueues one file at a time.

#### Query Rows Action

* You can query rows based on specific rulesets.

#### Add or Update Rows in CSV Action

* Row ID is used as a primary key for querying and updating. While it should be an ID, it can be any value. If a match is found with the Row ID, the existing row will be updated. If no match is found, a new row will be added. If there are multiple rows that match the same ID all matching rows will be updated.
