# File transfer

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> `rl file cp` copies a file or a directory between your computer and a workstation, in the style of `scp`.


`rl file cp` copies a file or a directory between your computer and a workstation, in the
style of `scp`. It needs no SSH setup, and a script can run it. Use it for a copy you make
once. For a folder that the workstation should see at all times, share the folder instead.

## Local and remote paths

One side of a copy is a local path, and the other is `workstation:path`. A colon before any
slash makes an argument remote, so a local file whose name contains a colon is written
`./name`.

- An empty workstation name, as in `:/tmp/notes.md`, picks the workstation that `rl shell`
  would pick, as
  [Workstation choice for shell and tmux](https://docs.ringleader.dev/workstations/connectivity/shells-remote-commands/#workstation-choice-for-shell-and-tmux)
  describes.
- An empty path, as in `my-box:`, is the login user's home directory.

## Destination of a copy

The destination is the path that will exist afterward. The one exception follows `cp(1)` and
applies to a single file only. A destination that names an existing directory, or ends in a
separator, receives the file under its own name.

A `-r` copy never adds a name to the destination. Running it twice does what running it once
did. `scp` would nest `dir/dir` on the second run.

## Guarantees of a copy

- A single file lands by a rename, so a transfer that fails leaves the destination exactly as
  it was.
- A `-r` copy merges into its destination. It is not atomic as a tree, though each file in it
  still is.
- A download never creates symbolic links. A directory that you copy up follows only the
  links that stay inside it.
- Any transfer that fails exits with a non-zero code and says what failed.

## File locations in a devcontainer workstation

The remote side of a copy is the file system that a bare `rl shell` lands on. On a
workstation that runs a devcontainer, that is inside the container. A path you copy to is
the path you then see in a shell. The workspace folder holds the same files either way,
because the container mounts it.

`--host` copies to and from the workstation's virtual machine instead. Use it for a path
outside the workspace folder.
[Devcontainer shell and file locations](https://docs.ringleader.dev/workstations/packages-tools-settings/devcontainers/#devcontainer-shell-and-file-locations)
shows where `scp`, `sftp`, `rsync` and `rl file cp` land.

## Copy a file to or from a workstation

To upload a file, put the local path first. To download one, put the workstation path first:

```bash
rl file cp ./notes.md my-box:/tmp/notes.md -n local
rl file cp my-box:/tmp/notes.md ./notes.md -n local
```

To copy a directory in either direction, add `-r`:

```bash
rl file cp -r ./src my-box:/home/dev/src -n local
```

<div class="callout callout-tip">
  <p class="callout-title">Share a folder instead of copying</p>
  <div class="callout-body">
    A shared folder keeps a folder on your Mac in view of a vz workstation, with no copy to
repeat. <a href="https://docs.ringleader.dev/workstations/providers/mac/#shared-folders-from-your-mac">Shared folders from your Mac</a>
explains them. qemu, hcs and the cloud providers share no folders. On those workstations,
<code>rl file cp</code> is the way to move files.
  </div>
</div>


## Next steps

- [`rl file cp`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-file-cp--r-src-dst) lists the flags of
  the command.
- [Connect to a workstation with SSH](https://docs.ringleader.dev/guides/connect-with-ssh/) adds
  Ringleader's SSH configuration to yours, so `scp`, `rsync` and `sftp` reach a workstation.
- [Copy a folder from your computer](https://docs.ringleader.dev/workstations/packages-tools-settings/code-dotfiles-trusted-folders/#copy-a-folder-from-your-computer)
  puts a folder on a workstation when it is created, rather than by hand.

