# 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](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/connector-shape/configuring-sftp-connections), 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F9JBpak3hHxjoZz2OgnzT%2Fget_and_move%20-%20flow%20.png?alt=media&#x26;token=f07b8b32-2422-47fd-bacc-08870e019135" alt=""><figcaption></figcaption></figure></div></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn8hT31RXr15yDkexZJE3%2Fpatchworks%20tile.png?alt=media&#x26;token=bfe93287-e388-4fc4-98d4-9f7f4d4ad145">patchworks tile.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F1MtOu3V7Ke3o5tmGd0Qm%2Fget_and_move%20files.png?alt=media&#x26;token=a6154898-bb2b-4128-a85c-216a01bd1484" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FLk4y0aH1PczueqSMTLXB%2Fsftp%20tile.png?alt=media&#x26;token=09c2c0cd-72cc-4c34-b43e-a494256f60d5">sftp tile.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FX3ySYJmLsQyG6xPr5cPN%2Fget_and_move_1_in.png?alt=media&#x26;token=8f388132-ca2f-4b9f-9dfd-dc08009c9969" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fj6MRefKqIGHibXcacRDK%2F1.png?alt=media&#x26;token=b29dc3c5-6a7d-406c-b1ea-4a42fa659f86">1.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fc1XDl00q1OfiKpcLDvAz%2Fget_and_move%20payload.png?alt=media&#x26;token=370c40a2-9b89-4c3f-b62e-1970b93968f5" alt=""><figcaption></figcaption></figure></div><p>On our remote server, the file is gone from <code>/myfiles/folderA/</code>:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FI5oX9lFBOsnA0lk65pqz%2Fget_and_move%20foldera.png?alt=media&#x26;token=2c4715c3-c9cf-412e-83f2-04ac8a2c2468" alt=""></p><p></p><p>And now it can be found in <code>/myfiles/folderB/</code>:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FZLgJ3TgVPe64N1YJmj5F%2Fget_and_move%20folderb.png?alt=media&#x26;token=7ab568fa-814f-4253-9ca9-ee3ce465b453" alt=""></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FHGWG2ZNqxBfnjG0EpNCG%2F2.png?alt=media&#x26;token=0364622b-8254-4551-9a68-9e2f142f330f">2.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F9CObZpHc5mtnUN5vi4ni%2Fget_and_move%20multi%20files%20-%20flow.png?alt=media&#x26;token=ca838c4b-ea0c-4451-8575-b5953d263025" alt=""><figcaption></figcaption></figure></div></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn8hT31RXr15yDkexZJE3%2Fpatchworks%20tile.png?alt=media&#x26;token=bfe93287-e388-4fc4-98d4-9f7f4d4ad145">patchworks tile.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fe4xerIOzXb22JLfvpev9%2Fget_and_move%20multi%20files%20-%20files%20before%20a.png?alt=media&#x26;token=85023c5f-1a1b-4723-b991-b96d499b24b8" alt=""><br><br>We are moving these files to <code>/myfiles/folderG</code> , which is currently empty:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn2eHLALZwMyNe0i91p2V%2Fget_and_move%20multi%20files%20-%20files%20before%20b.png?alt=media&#x26;token=a2ff07ec-3cda-4492-a2ed-21d2b91b7d4c" alt=""><br><br>We are keeping the same filenames.</td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FLk4y0aH1PczueqSMTLXB%2Fsftp%20tile.png?alt=media&#x26;token=09c2c0cd-72cc-4c34-b43e-a494256f60d5">sftp tile.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FCOCDxkg7JUK7QHFkxz6t%2Fget_and_move%20multi%20files%20-%20sftp%201.png?alt=media&#x26;token=2b5c7fbb-dcad-4afd-a62c-9d892640eb32" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FC4AoC1lQgSEhzuCsXXRW%2Fget_and_move%20multi%20files%20-%20sftp%201%20-%20payload.png?alt=media&#x26;token=82fa7daa-0438-448e-8423-129e33378979" alt=""></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fj6MRefKqIGHibXcacRDK%2F1.png?alt=media&#x26;token=b29dc3c5-6a7d-406c-b1ea-4a42fa659f86">1.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIb1mpkTKFAGo3OW3mWBW%2Fcopy%20multi%20-%20flow%20control%202.png?alt=media&#x26;token=8bcd0319-5c33-4f5c-9702-2d1d2039e7d2" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FN4w5esLRiS0FyVeYWpdL%2Fget_and_move%20multi%20files%20-%20flow%20control%201%20-%20payload.png?alt=media&#x26;token=85e0bd4b-d6d1-445b-958b-0f3a6102ba89" alt=""><br><br></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FeprQ8ZSUTgwLb4o6Jxvy%2F2.png?alt=media&#x26;token=c4fc14d2-0f0f-4487-8757-e4af51a32614">2.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIb1mpkTKFAGo3OW3mWBW%2Fcopy%20multi%20-%20flow%20control%202.png?alt=media&#x26;token=8bcd0319-5c33-4f5c-9702-2d1d2039e7d2" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FyP0jbTej2BDNMEuAxkrc%2Fget_and_move%20multi%20files%20-%20filter%20payload%20a.png?alt=media&#x26;token=58ada632-e63b-4e37-bab1-9086a127c47d" alt=""></p><p></p><p>Each one contains a single filename. For example:</p><p></p><p><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F1qftkTRwgNiQb2JMDRFX%2Fget_and_move%20multi%20files%20-%20filter%20payload%20b.png?alt=media&#x26;token=e611d4b8-286a-4f19-b6e6-f2c2ce8e1e60" alt=""><br><br></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FFGZGpJpRS5MqirFAp1J0%2F3.png?alt=media&#x26;token=1bf1b9f1-37ca-4926-9abc-121b4566bad7">3.png</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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FNqp6QBA2WYTHqzErcbAJ%2Fget_and_move%20multi%20files%20-%20sftp%202.png?alt=media&#x26;token=8a08f9c0-14ce-423b-93fc-a8ce7798cb8a" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fix6RkyLdCO1IUiL31Nwv%2Fget_and_move%20multi%20files%20-%20sftp%202%20-%20payload.png?alt=media&#x26;token=bebf6f2f-cdbd-4714-a756-cd61dc2c88fc" alt=""></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIrIZAXaH9BTFJp0S2TOI%2F4.png?alt=media&#x26;token=69d9e58f-dcaa-4af6-b4b5-60c912cd3f7a">4.png</a></td></tr><tr><td><p>On our remote server, all processed files are removed from <code>/myfiles/folderF/</code>:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FrwRHwMNZLSCI0G18M8Ay%2Fget_and_move%20multi%20files%20-%20files%20after%20b.png?alt=media&#x26;token=d8b155d2-ffeb-44e5-8c13-90d8c6c00132" alt=""></p><p></p><p>And now they can be found in <code>/myfiles/folderG/</code>:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FpzdS6b19NH1MOFrU6haa%2Fget_and_move%20multi%20files%20-%20files%20after%20a.png?alt=media&#x26;token=ace1b240-6c78-4706-8749-452182b265c0" alt=""><br><br></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FA3BkKRNbMlGfSlZaoO3q%2F5.png?alt=media&#x26;token=43be303f-79c7-4fc9-950a-7e0ccfdb836e">5.png</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](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/filter-shape).
{% endhint %}
