# Copy task

A Copy takes each file on the list and copies it to another place: another folder, or another server. Source and destination can be any two kinds of place the server can reach, so a Copy is also how a job downloads from a partner's SFTP server or uploads to cloud storage.

The task can also be a [Move](Task-Move.md): **Convert to Move Task** at the top of the form switches, and **Convert to Copy Task** switches back. Both have the same fields.

## Fields

| Field | What it does | On a new task |
|---|---|---|
| **Destination** | where each file goes, as an address that **ends in a file name**: `file:///data/in/{name}`, `sftp://user@host/in/{name}`. **Browse**, **Test**. The fields for that kind of address appear below it: see [Conditions on a task](Jobs-Conditions.md#a-form-that-changes-with-the-address). | |

"Destination path must have a file name or variable at the end". `{name}` keeps each file's name. To keep the folders below a [Find](Task-Find.md)'s folder as well, end with `{path}` in place of `{name}`.

### Before and during the copy

| Field | What it does | On a new task |
|---|---|---|
| **Wait x seconds to see if the file has changed** | before copying a file, wait and look whether its size or date changed. 0: do not check. | 2 |
| **Give up after x seconds** | if the file keeps changing this long, the task fails: "Timeout occurred waiting for file to not change" | 60 |
| **Temp name while in transit** | the file is written under this name and renamed when it is complete: `{name}.part`. Whatever watches the destination then never sees half a file. | empty |
| **Max Threads** | how many files are copied at the same time, 1 to 40 | 1 |
| **Connection Pool Source**, **Connection Pool Destination** | keep the connections open between files in place of logging in for each | off |
| **Convert Line Endings** | **No Change**, **CRLF - Windows**, **LF - Unix**, **CR - MacOS Classic**. "Warning: only use on ASCII files": it ruins anything that is not plain text. | No Change |

### When the file is already there

| Field | What it does | On a new task |
|---|---|---|
| (none ticked) | the file at the destination is overwritten | |
| **Copy Unique** | a name that is free is found, and the file goes there. **Optional pattern**: how the free name is made; `{iteration}` in it is the counter, as in `{stem}_{iteration}{ext}`. | off |
| **Block overwrite pattern** | if a file of this name is at the destination, the copy is left out: "Copy skipped, file exists". Usually `{name}`. | empty |
| **Resume** | a file that is partly there is continued. A file of the same size is left: "Copy skipped, files are the same size". | off |
| **Resume only on failure** | resume only when a try of this run broke off, not for files left from earlier | off |
| **Append** | the file is added to the end of the one that is there | off |

### Afterwards

| Field | What it does | On a new task |
|---|---|---|
| **Preserve modified date** | the copy gets the date of the original | on |
| **Validate transfer size matches server reported size?** | after the copy, the destination is asked for the file's size; a difference is a failure: "File download size difference" | off |
| **Rename source after copy** | the original is renamed, for example to `{name}.done`, to mark it as taken | empty |
| **Remove item from list after transfer** | the original is taken off the list | off |
| **After copying, add to list for future tasks.** | the copy is put on the list as well. "Be especially careful when using delete task as you could delete the original and copy." | off |

### When it fails

| Field | What it does | On a new task |
|---|---|---|
| **Retry failed copies x times** | | 0 |
| **Retry delay** | seconds between the tries | 0 |
| **Slow down retries with each failure.** | each delay is twice the one before | off |

### Encryption

A Copy can encrypt or decrypt with PGP while it copies, so that the plain file never lies on a disk in between:

| Field | What it does |
|---|---|
| **PGP Decrypt**, **Private Key Path**, **Private Key Password** | what is written is the decrypted file |
| **Verify**, **Public key to use for Verification** | the signature is checked while decrypting |
| **PGP Encrypt**, **Public Key Path** | what is written is encrypted for that key |
| **ASCII Armor** | the encrypted file is text |
| **Sign**, **Private key for Signing**, **Private Key Password** | the encrypted file is signed |
| **Add hinted decrypted size** | notes the plain size in the file, so that a CrushMFT server can show it |
| **Encryption cypher** | TRIPLE_DES, CAST5, BLOWFISH, AES_128, AES_192, AES_256, TWOFISH, DES, SAFER, IDEA. Use AES_256 unless the other side cannot. |
| **Test Key** | tries the key and its password |

For encrypting files where they are, see [PGP](Task-PGP.md).

## What it hands on

The **originals**, at the place they were copied from. So a [Delete](Task-Delete.md) behind a Copy removes the source files, and a second Copy sends the same files somewhere else.

| With | The list afterwards holds |
|---|---|
| nothing ticked | the originals |
| **After copying, add to list** | the originals and the copies |
| **Remove item from list after transfer** | nothing of what was copied |
| both | the copies only |

After a copy, each item also has `{md5}` of what was transferred, and its start and end times.

## Folders

- **The folder a file goes into must exist.** A Copy does not make it: the task fails with `java.io.FileNotFoundException … (No such file or directory)`. Put a [MakeDirectory](Task-MakeDirectory.md) before it.
- **A folder on the list is made at the destination.** So a Find with a **Depth** above 1, folders included, and a destination ending in `{path}` rebuilds a whole tree: the folders come first on the list and are made, then the files go into them.

## Things to know

- **Two seconds per file.** The check for changing files waits for each file, one after the other. For a hundred small files that is over three minutes. If the Find before it already checked (**Verify files are not changing**), set the wait to 0, or raise **Max Threads**.
- **Where a failure leaves things.** The task stops at the file that failed. The files before it are copied and stay.
- **The log** has two lines per file, "attempting copy (1) from:" and "to:", then "Copy finished:". The number is the try.
- **Run totals.** The Dashboard counts each copied file twice, once read and once written.
