> For the complete documentation index, see [llms.txt](https://ustb-os-lab.gitbook.io/2019/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ustb-os-lab.gitbook.io/2019/conf-linux/trans-files.md).

# Transfering Files Between Host and Container

Hermes versus Mercury.

With the SSH port, we can easily copy files between host and container.

## For GNU/Linux and macOS users

You will use the build-in `scp` tool, and do not need to install an extra one. To copy file from container to host, issue the following command in the host terminal:

```
scp -P 20022 username@127.0.0.1:SRC_PATH HOST_PATH
```

where

* `username` is the user name in Dockerfile. By default, it is `oslab`
* `SRC_PATH` is the path of the file in container to copy
* `HOST_PATH` is the path of the host to copy to

For example, the following command will copy a file in the container to a host path:

```
scp -P 20022 oslab@127.0.0.1:/home/oslab/a.txt .
```

To copy file from host to container, issue the following command in the host terminal:

```
scp -P 20022 HOST_SRC_PATH username@127.0.0.1:DEST_PATH
```

where

* `HOST_SRC_PATH` is the path of the host file to copy
* `username` is the user name in Dockerfile. By default, it is `oslab`
* `DEST_PATH` is the path in the container to copy to

For example, the following command will copy a folder in host into the container:

```
scp -P 20022 hello.c oslab@127.0.0.1:/home/oslab
```

## For Windows users

Windows has no build-in `scp` tool, and you have to download one manually. Download the latest release version of `pscp.exe` [here](http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html). Change the current directory of PowerShell to the one with `pscp.exe` in it. Then use the following commands to transfer files.

```
./pscp -P 20022 username@127.0.0.1:SRC_PATH HOST_PATH
./pscp -P 20022 HOST_SRC_PATH username@127.0.0.1:DEST_PATH
```

The explanation of these commands is similar to `scp` above. Refer to them for more information.

## Have a try!

1. New a text file with casual contents in the host.
2. Copy the text file to the container.
3. Modify the content of the text file in the container.
4. Copy the modified file back to the host.

Check whether the content of the modified file you get after the last step is expected. If it is the case, you are done!
