scp -r: Copy Directories Recursively
scp -r copies a directory and all of its contents to or from a remote host.
Deploying a built site or a directory of assets needs -r. Watch how the destination path and trailing slashes shape where files land.
What it does
scp -r recursively transfers a directory tree. Without -r, scp refuses a directory source. Unlike rsync, scp does not treat a trailing slash on the source specially; it copies the named directory into the destination directory.
Common usage
# copy the whole build directory to the server
scp -r ./dist user@host:/srv/app/
# pull a directory of logs back to the runner
scp -r user@host:/var/log/myapp ./logs
# combine recursive with a key and compression
scp -r -C -i deploy_key ./dist prod:/srv/app/Options
| Flag | What it does |
|---|---|
| -r | Recursively copy directories |
| -p | Preserve times and permissions |
| -C | Compress during transfer |
| -i <key> | Identity file |
| -P <port> | Remote port (uppercase) |
In CI
For large trees consider whether rsync over ssh would be faster, since scp re-sends everything each run. If you only mean to copy a directory's contents into an existing target, name the contents explicitly; scp -r ./dist host:/srv/app puts a dist directory inside /srv/app.
Common errors in CI
scp: ./dist: not a regular file means you omitted -r on a directory. "scp: /srv/app/dist: Permission denied" is a remote permission issue on the target path. "No such file or directory" on the destination means an intermediate directory does not exist; scp does not create parent paths, so mkdir them first over ssh.