How do I copy a folder from remote to local using scp?
By FoxLearn 12/11/2024 7:48:42 AM 50
How do I copy a folder from remote to local host using scp?
Open iTerm2 Terminal on macOS, then use scp -r
to Copy a Directory
scp -r username@host:/path/to/foo /home/user/desktop/
-r
: Recursively copy the entire directory.username
: Your SSH username on the remote server.host
: The IP address or hostname of the server. (your.server.example.com)/path/to/foo
: Path to the folder on the remote server you want to copy./home/user/desktop/
: Local directory where you want to save the folder.
By not including the trailing '/' at the end of 'foo', you will copy the directory itself (along with its contents), rather than just the contents of the directory.
Without the trailing /
: The entire directory (including its contents) will be copied to the destination.
scp -r user@host:/path/to/foo /path/to/local/
This copies the foo
directory itself, including all its files and subdirectories, into /path/to/local/
With the trailing /
: Only the contents of the directory (not the directory itself) will be copied into the destination directory.
scp -r user@host:/path/to/foo/ /path/to/local/
This copies only the contents of foo
into /path/to/local/
, not the foo
directory itself.