---
schema_version: "1"
id: 16948c8ea8c118f2f79d8b12bddeb1165442e056a617213fe5bc0d3cd3730def
title: Write 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-write.md
canonical_url: https://docs.mulesoft.com/sftp-connector/latest/sftp-write
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 5c6351bfb438a0becbe19fbffc18b30b587c096ee231f1347118a5cf440a7c31
description: MuleSoft Documentation Site
release: "2.7"
latest: true
---
---
product: SFTP Connector
version: 2.7
is-latest-version: true
---

# Write 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 **Write** operation that writes content into
the given path on demand.

## Configure the Write Operation in Studio

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

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

2.  Drag the **Write** 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 **Path** field to `output.csv` to set the path of the file to
    write.  
    By default, the connector writes whatever is in the message payload.

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

In the **Configuration XML** editor, the `<sftp:write>` configuration looks like this:

```xml
<sftp:write path="output.csv" />
```

## Use Embedded DataWeave Transformations

If you place a **Transform Message** component before the **Write** operation, the message payload
changes, and that impacts the operation that is placed after the **Write** operation. Therefore, if
the payload is in a different format and you need to transform it before writing it, you can place
the transformation inside the **Content** field of the **Write** operation to generate content to be
written without affecting the message in transit.

The following example places the DataWeave transformation in the **Content** field:

![Write operation configuration in Studio with Content field](/mulesoft/current/en-us/sftp-connector/latest/_images/sftp-write-operation-2.png)

In the **Configuration XML** editor, the configuration looks like this:

```xml
<sftp:write path="output.csv">
  <sftp:content>#[%dw 2.0
                   output application/csv
                   ---
                   payload.customers.email
                  ]
  </sftp:content>
</sftp:write>
```

## Write into Directories

Because the **Write** operation fails by default if you set nonexistent directories in the **Path**
field, set the **Create parent directories** field to **True (Default)** to automatically create any
missing directories.

The following example shows that if any of the `a`, `b`, or `c` directories set in the **Path**
field do not exist, the connector creates them:

![.Write operation configuration with Create parent directories](/mulesoft/current/en-us/sftp-connector/latest/_images/sftp-write-operation-3.png)

In the **Configuration XML** editor, the configuration looks like this:

```xml
<sftp:write path="a/b/c/myFile.txt" />
```

## Use Write Strategy

Use the **Write strategy** field to configure the strategy to write the file. You can configure the
field to select either of these strategies:

- `STANDARD`  
  This is the default strategy that you can use in the `APPEND`, `OVERWRITE`, and `CREATE_NEW`
  modes.

- `CUSTOM`  
  This strategy enables you to manually specify the offset for the server to write the file in
  `APPEND` mode, particularly only for older SFTP servers that do not directly support write modes.

Additionally, you can configure the buffer size for writing into the file via the **Buffer size for
write strategy** field.

> [!NOTE] Use the `CUSTOM` write strategy with the `CUSTOM_APPEND` mode because it isn’t applicable
> to the `OVERWRITE` or `CREATE_NEW` modes. Use this strategy only if the `STANDARD` strategy
> results in errors during file writing in `APPEND` mode. Concurrency isn’t maintained for servers
> that don’t follow SFTP guidelines.

The following example shows the configuration for both fields:

![Write operation configuration with write strategy and buffer size for write strategy fields](/mulesoft/current/en-us/sftp-connector/latest/_images/sftp-write-operation-4.png)

In the **Configuration XML** editor, the configuration looks like this:

```xml
<sftp:write  path="testFile.csv" mode="APPEND" writeStrategy="CUSTOM" bufferSizeForWriteStrategy="BUFFER_SIZE_16KB" config-ref="SFTP_Config"/>
```

## Write to Existing Files

When writing content to a file, set the **Write Mode** field to any of the following modes:

- **OVERWRITE (Default)**  
  If the file exists, overwrite it completely.

- **APPEND**  
  If the file exists, add its content to the end of an existing file.

- **CREATE\_NEW**  
  Create a new file. If the file already exists, then you receive an error.

## Locks

The **Write** operation supports locking similar to the **Read** operation. The main difference is
that the lock releases automatically after the **Write** operation finishes. Set the **Lock** field
to any of the following modes:

- **TRUE**

- **FALSE (Default)**

## See Also

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

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