# copy (FTP command)

## Overview

The `copy` command copies a file from one location on the remote server to another location on the remote server. The copied file remains in the source directory and no content is loaded into the flow.

## Need to know

* The `copy` command can be used to [target specific files](#copying-a-specific-file-from-one-directory-to-another) in one step. You can [copy all files in a directory, or selected files (using regex)](#copying-all-files-from-one-directory-to-another) but this requires multiple steps rather than a single `copy` operation.&#x20;
* Regular expressions are supported when defining files to be copied with the `copy` command.
* When copying [all files from one directory to another](#copying-all-files-from-one-directory-to-another), subfolders are not included.

## Connection settings

When [configuring an SFTP connector](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/connector-shape/configuring-sftp-connections.md), three fields should be updated:

| FTP command                                                                             | Root                                              | Path                           |
| --------------------------------------------------------------------------------------- | ------------------------------------------------- | ------------------------------ |
| FTP command followed by the target directory - i.e. where should the file(s) be copied? | The common root to source and target directories. | The source directory and files |

## Examples

* [Copy a specific file from one directory to another](#copying-a-specific-file-from-one-directory-to-another)
* [Copy all files from one directory to another](#copying-all-files-from-one-directory-to-another)

### Copying a specific file from one directory to another

* [Scenario](#scenario)
* [The steps](#the-steps)

#### Scenario

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p>Our process flow is configured as follows:</p><div><figure><img src="/files/puckZClBhtqnwsCdfRvW" alt=""><figcaption></figcaption></figure></div></td><td><a href="/files/rI8jPerjv9MFfSCvdBbq">/files/rI8jPerjv9MFfSCvdBbq</a></td></tr><tr><td>In this flow, we need to copy a file named <code>orders.json</code> from <code>/myfiles/folderB</code> on the remote server, to <code>/myfiles/folderB</code> , keeping the same filename:<br><br><img src="/files/hBk4OMONCHBfDdPojnfl" alt=""></td><td><a href="/files/2vpVY6Q37YrYqTgeZirK">/files/2vpVY6Q37YrYqTgeZirK</a></td></tr></tbody></table>

#### The steps

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p><strong>Connector settings</strong></p><p>Our SFTP shape is configured as follows: </p><div align="left"><figure><img src="/files/Qlb0lDMAGZRg6t9Ps1DT" alt=""><figcaption></figcaption></figure></div><ul><li>Start looking for the file to get, from the <code>root</code>, which is defined as: <code>/myfiles/</code></li><li>Check the <code>path</code> for the file to copy, which is defined as: <code>folderB/orders.json</code></li><li>Copy this file to the <code>path</code> (from the <code>root</code>) which is specified immediately after the <code>ftp command</code>. This is defined as: <code>copy:folderA/{{current_filename}}</code></li></ul></td><td><a href="/files/oMb9sRQ3X0NcUlY4i8Mk">/files/oMb9sRQ3X0NcUlY4i8Mk</a></td></tr><tr><td><p>On our remote server, the file remains in <code>/myfiles/folderB/</code>:<br><br><img src="/files/QUjKybVfXcVhGLmcv18c" alt=""></p><p></p><p>And it can also be found in <code>/myfiles/folderA/</code>:<br><br><img src="/files/rU35VyijOSWEKjWgpv6N" alt=""><br><br></p></td><td><a href="/files/J6YFhcQQMgUmK2sBQwdu">/files/J6YFhcQQMgUmK2sBQwdu</a></td></tr></tbody></table>

### Copying all files from one directory to another

* [Scenario](#scenario)
* [The steps](#the-steps)

#### Scenario

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p>Our process flow is configured as below:</p><div><figure><img src="/files/etd4VD1lsUPRPP4Tj8bM" alt=""><figcaption></figcaption></figure></div></td><td><a href="/files/rI8jPerjv9MFfSCvdBbq">/files/rI8jPerjv9MFfSCvdBbq</a></td></tr><tr><td>In this flow, we need to copy all files in <code>/myfiles/folderC</code> on the remote server:<br><br><img src="/files/bZNmyqVje0zQgT3drj6q" alt=""><br><br>...to <code>/myfiles/folderD</code> , which is currently empty:<br><br><img src="/files/u8qs1BKURanPOQmya1Op" alt=""><br><br>We are keeping the same filenames.</td><td><a href="/files/2vpVY6Q37YrYqTgeZirK">/files/2vpVY6Q37YrYqTgeZirK</a></td></tr><tr><td></td><td></td></tr></tbody></table>

#### The steps

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p><strong>Connector settings for SFTP shape 1</strong></p><p>Our first <code>SFTP connector</code> step is configured as follows: </p><div align="left"><figure><img src="/files/CXnlcLl2aMC5KFBPMqi1" alt=""><figcaption></figcaption></figure></div><ul><li>Use the <code>SFTP GET user pass</code> endpoint.</li><li>Use <code>list</code> as the <code>FTP command</code>.</li><li>Look for files in the <code>root</code>, which is defined as: <code>/myfiles/folderC</code></li><li>Since there's no specific file to target, we leave the <code>path</code> empty</li></ul><p>When the flow runs, the SFTP shape outputs a single payload which contains all file names found in <code>/myfiles/folderC</code>, as an array:<br><br><img src="/files/q5Gr7EppKDipKy8LIQUh" alt=""></p></td><td><a href="/files/oMb9sRQ3X0NcUlY4i8Mk">/files/oMb9sRQ3X0NcUlY4i8Mk</a></td></tr><tr><td><p><strong>Flow control settings</strong>  </p><p>We use a <code>flow control</code> step to extract each file name into its own payload:  </p><div align="left"><figure><img src="/files/7ETkA4a4bkbDnaBDnrOy" alt=""><figcaption></figcaption></figure></div><p>Here we create batches of <code>1</code>, so we get one payload per file name. <br><br>When the flow runs, this shape outputs multiple payloads, each containing a single filename. For example:</p><p><img src="/files/MxbuYgO2hSwjpsbtofGV" alt=""><br><br></p></td><td><a href="/files/vHd6zemYZQgFjIQ5t6sj">/files/vHd6zemYZQgFjIQ5t6sj</a></td></tr><tr><td><p><strong>Connector settings for SFTP shape 2</strong></p><p>Our final <code>SFTP connector</code> step is configured as follows: </p><div align="left"><figure><img src="/files/EhVfgIPRc2t0s5hWIU2U" alt=""><figcaption></figcaption></figure></div><ul><li>Since we are updating the remote server (as opposed to retrieving files) the <code>SFTP PUT user pass</code> endpoint is selected.</li><li>The <code>root</code> is defined as <code>/myfiles/</code>, which is the common root for both source (<code>folderC</code>) and target (<code>folderD</code>) directories.   </li><li>The <code>path</code> defines which files are copied. It's set as <code>folderC/[[payload.0]]</code> which means: <em>look in <code>folderC</code> (from the <code>root</code>) for a filename resolved from the first value in the incoming payload.</em> Keep in mind that this step repeats for each incoming payload from the previous flow control step - i.e. for each file.</li><li>The <code>ftp command</code> includes the <code>copy</code> command, immediately followed by our target directory: <code>copy:folderD/{{current_filename}}</code> .  </li></ul></td><td><a href="/files/CaDlvrcB9Vd1DmUVmK9d">/files/CaDlvrcB9Vd1DmUVmK9d</a></td></tr><tr><td><p>On our remote server, all files remain in <code>/myfiles/folderC/</code>:<br><br><img src="/files/hPayWUzoPAFRB6acC9dE" alt=""></p><p></p><p>And they can also be found in <code>/myfiles/folderD/</code>:<br><br><img src="/files/VaX0D9tYhr0c6DoSaoMN" alt=""><br><br></p></td><td><a href="/files/6Kl8Lg5qstCSP9NLcsMp">/files/6Kl8Lg5qstCSP9NLcsMp</a></td></tr></tbody></table>

{% hint style="info" %}
In this example we copied ALL files from one folder to another. If we needed to copy a selection of files, we could add a [filter shape](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/filter-shape.md) after the [flow control ](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/flow-control-shape.md)- for example:

![](/files/gvfbH4REzFzojrmd7UuQ)\
\
Here we define the `field name` as `0`, so the first value in our payload (bearing in mind we only have one field in each payload).

We set the filter `type` to `string` and the `operator` to `regex`, then provide our regular expression. In this example (`/^old.*/i`), only files starting with 'old' will be copied.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/connector-shape/configuring-sftp-connections/valid-ftp-commands/copy-ftp-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
