how to copy a folder via ssh to local machine
- User
how to copy a folder via ssh to local machine
Assistant
To copy a folder from a remote machine to your local machine via SSH, you can use
scp(secure copy) orrsync. Here are the most common methods:Using scp
To copy a folder recursively:
scp -r username@remote_host:/path/to/remote/folder /path/to/local/destinationFor example:
scp -r user@192.168.1.100:/home/user/documents ~/Downloads/Using rsync
Rsync is often preferred for larger transfers as it can resume interrupted transfers and only copies changed files:
rsync -avz username@remote_host:/path/to/remote/folder /path/to/local/destinationFor example:
rsync -avz user@192.168.1.100:/home/user/documents ~/Downloads/The flags mean:
-a: archive mode (preserves permissions, timestamps, etc.)-v: verbose (shows progress)-z: compress data during transfer
Additional options
If you're using a non-standard SSH port:
scp -P 2222 -r username@remote_host:/path/to/folder /local/path rsync -avz -e "ssh -p 2222" username@remote_host:/path/to/folder /local/pathIf you have an SSH key in a specific location:
scp -i ~/.ssh/mykey.pem -r username@remote_host:/path/to/folder /local/path rsync -avz -e "ssh -i ~/.ssh/mykey.pem" username@remote_host:/path/to/folder /local/pathNote: Make sure you have the necessary permissions to read the remote folder and write to the local destination.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.