---
schema_version: "1"
id: 8a231bef3f3a33c5bce0a61429f5dc8b6426a8abe93b1ff098bc0dfc94c31340
title: Read a File Using the SFTP Connector Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/sftp-connector/latest/sftp-read.md
canonical_url: https://docs.mulesoft.com/sftp-connector/latest/sftp-read
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 5f11aeb0ae33c16b9ec5b7982174f25d33056f880aa919b0b4c8e5956ac6130b
description: MuleSoft Documentation Site
release: "2.7"
latest: true
---
---
product: SFTP Connector
version: 2.7
is-latest-version: true
---

# Read a File Using the SFTP Connector Example

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Anypoint Connector for SFTP (SFTP Connector) provides a **Read** operation that reads a file at any
point in the flow. The operation reads the file in the given path and returns a Mule message with
the following attributes:

- The file’s content as the payload

- The file’s metadata in the message attributes

- If the file does not exist, you receive an `SFTP:ILLEGAL_PATH` error

  Note that the operation does not read directories.

## Configure the Read Operation in Studio

To add and configure the **Read** operation in Studio, follow these steps:

1.  In the **Mule Palette** view, search for `sftp` and select the **Read** operation.

2.  Drag the **Read** operation onto the Studio canvas.

3.  In the **General** tab of the operation configuration screen, click the plus sign (**+**) next
    to the **Connector configuration** field to access the global element configuration fields.

4.  Specify the connection information and click **OK**.

5.  In the **General** tab, set the **File Path** field to the path of the file to read, for
    example, `#[path]`.

6.  In the **Advanced** tab, set the **MIME Type** field to `application/xml` and the **Encoding**
    field to `ISO 10646/Unicode(UTF-8)`.

The following screenshot shows the **Read** operation configuration:

![Read operation configuration in Studio](/mulesoft/current/en-us/sftp-connector/latest/_images/sftp-read-operation.png)

Figure 1. Read operation configuration

In the XML editor, the `<sftp:read>` configuration looks like this:

```xml
<sftp:read path="#[path]"
  lock="true|false"
  outputEncoding="UTF-8"
  outputMimeType="application/xml" />
```

## Transactions Per Second

The following table compares the total requests per second (TPS) and average success TPS for the
**Read** operation of the SFTP Connector versions:

<table><colgroup><col> <col> <col> <col> <col> <col> <col></colgroup><thead><tr><th>Connector version</th><th>Mule runtime engine version</th><th>Total requests for v1.6.1</th><th>Total requests for v2.0.1</th><th>Average success TPS for v1.6.1</th><th>Average success TPS for v2.0.0</th><th>Percentage of decreased TPS performance</th></tr></thead><tbody><tr><td><p>1.6.1 vs 2.0.0</p></td><td><p>4.4.1</p></td><td><p>301,377.40</p></td><td><p>247,614.40</p></td><td><p>1,674</p></td><td><p>1,375.60</p></td><td><p>-18</p></td></tr><tr><td><p>1.6.1 vs 2.0.0</p></td><td><p>4.5.0</p></td><td><p>326,915.80</p></td><td><p>247,296.20</p></td><td><p>1,816</p></td><td><p>1,374</p></td><td><p>-24</p></td></tr></tbody></table>

## MIME Types and Encoding

Each connector tries to determine a file’s MIME type from its extension. You can force the MIME type
to a different value with the **MIME Type** (`outputMimeType`) parameter.

The same process works for encoding. By default, the connector assumes that the default encoding in
the Mule runtime matches the MIME type of the file, however, you can set the encoding through the
**Encoding** (`outputEncoding`) parameter.

## Why MIME Types Matter

DataWeave expressions are embeddable inside operations that generate payloads and other values.
Having the correct MIME type set helps DataWeave auto-assign types and also generate the correct
outputs. Also, maximizing the use of DataSense’s functionality improves the user experience.

## File Locks

File system level locks are not possible in FTP or SFTP, so each operation uses a Mule lock that
protects only the file from other flows in the same Mule application. These locks do not protect the
file from external processes. However, if the Mule application is running on a cluster, the lock is
distributed.

The file lock is automatically released when any of the following occurs:

- The Mule flow that locked the file ends

- The file content has been fully read

> [!NOTE] If the file is already locked by someone else, the connector cannot unlock it, resulting
> in a `FTP:FILE_LOCK` error.

## See Also

- [SFTP Connector Examples](https://docs.mulesoft.com/sftp-connector/latest/sftp-examples)

- [Salesforce Help](https://help.salesforce.com)
