Tutorial

How to copy a directory over SSH (scp -r, rsync, sftp)

scp needs -r to copy a folder: scp -r ./folder user@host:/path/. For large or repeated transfers use rsync; on mobile use SFTP. The common errors (the -r and capital -P gotchas) and which tool to pick.

TA TermAI·June 14, 2026·5 min read

How to copy a directory over SSH

scp won't copy a folder unless you tell it to recurse — add -r:

scp -r ./myfolder user@host:/remote/path/

That copies the whole directory tree. For large or repeated transfers, rsync is better (it resumes and skips unchanged files), and on mobile a SFTP app does it with a tap. Here's each, and the common errors.

scp -r — the direct way

# local folder → server
scp -r ./project user@host:/var/www/

# server folder → local
scp -r user@host:/var/log/nginx ./logs

# non-default port (note: capital -P)
scp -P 2222 -r ./project user@host:/var/www/

The catch most people hit: scp uses a capital -P for the port (lowercase -p preserves timestamps). Mixing them up is the usual "scp not working" cause.

rsync — better for big or repeated copies

For anything large, syncing, or run more than once, use rsync — it only transfers what changed and resumes if interrupted:

rsync -avz ./project/ user@host:/var/www/project/

# with a non-default port or a specific key:
rsync -avz -e "ssh -p 2222 -i ~/.ssh/mykey" ./project/ user@host:/var/www/project/

-a preserves permissions and recurses, -v is verbose, -z compresses. Note the trailing slash on the source (project/) — it copies the contents; without it you copy the folder itself. (To use a specific key with rsync, see use a specific SSH key.)

sftp — interactive, and get -r

If you prefer browsing, sftp downloads a directory with get -r:

sftp user@host
sftp> get -r /remote/folder

More on the three tools and when to use each: transfer files over SSH.

Common errors

  • "not a regular file" / nothing copied — you forgot -r on a directory.
  • Wrong port / connection refused — use -P (capital) with scp; check the port.
  • Permission denied — you can't write to the destination path, or key auth failed (publickey guide).

Copying folders from a phone

Typing scp -r with two remote paths on a touch keyboard is exactly the kind of thing mobile makes painful. A SFTP-capable client turns it into browsing: open the server's filesystem, pick a folder, download or upload it. TermAI's SFTP lets you browse, transfer, and even edit files on the server directly; for a scripted copy, the AI assistant will write the right scp -r or rsync command for you to review.

TermAI suggesting an rsync command to copy a directory
Instead of typing scp -r with two remote paths on glass, browse over SFTP — or ask the AI to write the exact rsync/scp command.

FAQ

How do I scp a directory?
Add -r to recurse: scp -r ./folder user@host:/path/. For a non-default port use a capital -P.

Why won't scp copy my folder?
Without -r, scp refuses directories ("not a regular file"). Add -r. Also check you used capital -P for the port.

scp or rsync for a directory?
scp -r for a one-off small copy; rsync for anything large, repeated, or that might be interrupted — it resumes and skips unchanged files.

How do I download a directory with sftp?
Connect with sftp user@host, then run get -r /remote/folder.

Quick Facts

  • scp a folder: scp -r ./folder user@host:/path/ (the -r is required)
  • Port: scp uses capital -P (lowercase -p = preserve times)
  • Large/repeated: rsync -avz src/ user@host:/dest/ — resumes, skips unchanged
  • sftp: get -r /remote/folder
  • Mobile: browse and transfer over SFTP instead of typing paths
Try TermAI

Start with Free on iOS or Android. Current connection limits, AI allowances and subscription terms are shown in the app before purchase.

TA

Published by the TermAI team. Product comparisons include our own software. Only material that states its environment, method and results should be treated as a verified test.