# get\_and\_move (FTP command)

### Overview

The `get_and_move` command retrieves the file content, loads it into the flow as a payload, and then moves the file to the specified directory on the remote server. &#x20;

## Need to know

* You can use the `get_and_move` command to [target specific files](#copying-a-specific-file-from-one-directory-to-another) in one step. In this scenario, the file content is loaded into the flow as a payload.
* You can use the `get_and_move` command to [get & move multiple files ](#copying-all-files-from-one-directory-to-another)[(using regex in a filter)](#copying-all-files-from-one-directory-to-another) [or all files in a directory](#copying-all-files-from-one-directory-to-another), but this requires multiple steps rather than a single `get_and_move` operation. In this scenario, content from files is NOT loaded into the flow; instead, payloads will contain the filename.&#x20;
* Regular expressions are supported when [targeting single files](#getting-and-moving-a-specific-file) to `get_and_move`.
* When getting and moving [all files from a directory](#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 moved? | The common root to source and target directories. | The source directory and file(s). |

## Examples

* [Get and move a specific file](#copying-a-specific-file-from-one-directory-to-another)
* [Get & move multiple files](#getting-and-moving-multiple-files)&#x20;

### Getting & moving a specific file&#x20;

* [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/a03buZhKWr8SluLo8nvH" alt=""><figcaption></figcaption></figure></div></td><td><a href="/files/rI8jPerjv9MFfSCvdBbq">/files/rI8jPerjv9MFfSCvdBbq</a></td></tr><tr><td><p>In this flow, we need to retrieve content from a file named <code>orders.json</code> which is located in <code>/myfiles/folderA</code> on the remote server:<br><br><img src="/files/mJla1DVrLI7SB2Kn0XjG" alt=""></p><p></p><p>Then we want to move this file to <code>/myfiles/folderA</code> and keep the same filename.</p></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/Lzjuf6V7kvmJ4kfXcPHu" 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 get, which is defined as: <code>folderA/orders.json</code></li><li>Having loaded content from this file, move it 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>get_and_move:folderB/{{current_filename}}</code></li></ul></td><td><a href="/files/oMb9sRQ3X0NcUlY4i8Mk">/files/oMb9sRQ3X0NcUlY4i8Mk</a></td></tr><tr><td><p><strong>Payload &#x26; SFTP server</strong> </p><p>When the process flow is run, the payload for the SFTP shape shows the content retrieved from <code>/myfiles/folderA/orders.json</code> :</p><div align="left"><figure><img src="/files/Geec7WoFgfVkUZHieCaE" alt=""><figcaption></figcaption></figure></div><p>On our remote server, the file is gone from <code>/myfiles/folderA/</code>:<br><br><img src="/files/JsgbqYESAkPMlNik8KWp" alt=""></p><p></p><p>And now it can be found in <code>/myfiles/folderB/</code>:<br><br><img src="/files/hBk4OMONCHBfDdPojnfl" alt=""></p></td><td><a href="/files/J6YFhcQQMgUmK2sBQwdu">/files/J6YFhcQQMgUmK2sBQwdu</a></td></tr></tbody></table>

### Getting & moving multiple files

* [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/Gacn2ZOklMm7JceYw7aO" alt=""><figcaption></figcaption></figure></div></td><td><a href="/files/rI8jPerjv9MFfSCvdBbq">/files/rI8jPerjv9MFfSCvdBbq</a></td></tr><tr><td>In this flow, we need to <code>get and move</code> all files in <code>/myfiles/folderF</code> which start with 'old', on the remote server:<br><br><img src="/files/hcCE3vmGQCJFsQhYWnX2" alt=""><br><br>We are moving these files to <code>/myfiles/folderG</code> , which is currently empty:<br><br><img src="/files/cx503nsV0Y9ttjUjzeyR" alt=""><br><br>We are keeping the same filenames.</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 for SFTP shape 1</strong></p><p>Our first <code>SFTP connector</code> step is configured with a <code>list</code> command, as follows: </p><div align="left"><figure><img src="/files/MpG0GbXks0ueYhbd7h8R" 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/folderF</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/folderF</code>, as an array:<br><br><img src="/files/skN0hcAbo4KQxVELIIug" 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 a multiple payloads, each containing a single filename. For example:</p><p><img src="/files/YazsjtSrCMTyrCfQ5e5x" alt=""><br><br></p></td><td><a href="/files/vHd6zemYZQgFjIQ5t6sj">/files/vHd6zemYZQgFjIQ5t6sj</a></td></tr><tr><td><p><strong>Filter shape settings</strong>  </p><p>We use a filter shape to extract only the file names that we want to process. To achieve this, we define a single filter rule, as below:  </p><div align="left"><figure><img src="/files/7ETkA4a4bkbDnaBDnrOy" alt=""><figcaption></figcaption></figure></div><p>Here we define the <code>field name</code> as <code>0</code>, so the first value in our payload (bearing in mind we only have one field in each payload).<br></p><p>We set the filter <code>type</code> to <code>string</code> and the <code>operator</code> to <code>regex</code>, then provide our regular expression. <br><br>Our regular expression is set to <code>/^old.*/i</code>, so only files starting with 'old' will be extracted for onward processing.<br><br>When the flow runs, this shape outputs three payloads:</p><p></p><p><img src="/files/NluaRtvkCGnKFwmdQTN4" alt=""></p><p></p><p>Each one contains a single filename. For example:</p><p></p><p><img src="/files/TTe0M40OpxWVm4fCii50" alt=""><br><br></p></td><td><a href="/files/CaDlvrcB9Vd1DmUVmK9d">/files/CaDlvrcB9Vd1DmUVmK9d</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 to get and move files with the names received from the previous <code>filter</code> shape: </p><div align="left"><figure><img src="/files/l8fdUmzaZ2ygxbIWIgE7" 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>folderF</code>) and target (<code>folderG</code>) directories.   </li><li>The <code>path</code> defines which files are retrieved  and moved. It's set as <code>folderF/[[payload.0]]</code> which means: <em>look in <code>folderF</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>get_and_move</code> command, immediately followed by our target directory: <code>copy:folderG/{{current_filename}}</code> .  </li></ul><p>When the flow runs, this shape outputs a payload for each processed file, each one containing the file name. For example:<br><br><img src="/files/MsHQjCcilXlFxqdQ6F88" alt=""></p></td><td><a href="/files/6Kl8Lg5qstCSP9NLcsMp">/files/6Kl8Lg5qstCSP9NLcsMp</a></td></tr><tr><td><p>On our remote server, all processed files are removed from <code>/myfiles/folderF/</code>:<br><br><img src="/files/CIyA8hX63U9bTwrIznuc" alt=""></p><p></p><p>And now they can be found in <code>/myfiles/folderG/</code>:<br><br><img src="/files/2zj6Z93riXuaFbpN5OCn" alt=""><br><br></p></td><td><a href="/files/gN3YFcn9cY0fEfvafRyF">/files/gN3YFcn9cY0fEfvafRyF</a></td></tr></tbody></table>

{% hint style="info" %}
In this example we moved selected files from one folder to another. If we needed to copy ALL files, we could simply remove the [filter shape](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/filter-shape.md).
{% 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/get_and_move-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.
