Contact Free trial Login

Write a File Using the FTP Connector

A Write operation is available to the File, FTP, and SFTP connectors. For these connectors, the operation writes content into the given path on demand. It supports common use cases described below.

Embedded DataWeave Transformations

By default, the connector writes whatever is in the message payload:

Example: FTP Connector
<ftp:write path="output.csv" />

However, if the payload is a different format (for example, not CSV) and you need to transform it before writing it, what do you do? If you place a Transform component before the Write operation, the message payload changes and that impacts the operation that is placed after the Write operation.

To avoid this undesired impact, you can place the transformation inside the Write operation to generate content that is written without producing a side effect on the message in transit.

The next example uses the FTP connector to write the content:

Example: Transformation within an FTP Write Operation
<ftp:write path="output.csv">
  <ftp:content>#[%dw 2.0
                 output application/csv
                 ---
                 payload.customers.email
                ]
  </ftp:content>
</ftp:write>

Write into a Directory

If any of the a, b, or c directories in the example below do not exist, the Write operation fails by default. However, if you set the createParentDirectories to true, the connector automatically creates any missing directories.

Example: FTP Connector writes to a Directory
<ftp:write path="a/b/c/myFile.txt" />

Write to Existing Files

There are several file write modes you can use when writing content to a file:

  • OVERWRITE: 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

This Write operation supports locking similar to the Read operation. The main difference is that the lock releases automatically after the Write operation finishes.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub