SCP Command Operation Guide| Secure file transfer- GoTool Online Toolkit

开发工具指南

GoTool.top commonly used scp operation documents, developers can efficiently build SCP operation guidelines.

使用说明

scp Command Quick Reference

Basic Syntax

scp [options] [source_path] [destination_path]

Common Usage Examples

1. Upload local file to remote server
scp ./file.txt user@192.168.1.10:/home/user/
2. Download file from remote server to local
scp user@192.168.1.10:/home/user/file.txt ./file.txt
3. Upload directory to remote server
scp -r ./mydir user@192.168.1.10:/home/user/
4. Download directory from remote server to local
scp -r user@192.168.1.10:/home/user/mydir ./mydir
5. Use specific port (e.g., 2222)
scp -P 2222 ./file.txt user@192.168.1.10:/home/user/
6. Use specific private key file
scp -i ~/.ssh/id_rsa ./file.txt user@192.168.1.10:/home/user/

Common Options

Option Description
-r Recursively copy entire directories
-P Specify remote host port (note: uppercase P)
-i Specify SSH private key file
-C Enable compression to improve transfer speed
-p Preserve file modification times, permissions
-q Quiet mode, suppress progress information

Path Format

Type Example
Local path ./file.txt or /home/user/file.txt
Remote path user@host:/path/to/file.txt

Common Error Troubleshooting

Error Possible Cause
Permission denied Invalid SSH key, or no write permission to remote directory
No such file or directory Incorrect source or destination path
Connection refused Target port unreachable or SSH service not running
Host key verification failed First time connecting to remote host, host fingerprint not accepted. Try ssh login first

Additional Tips

Copy file between two remote servers
scp user1@host1:/path/file.txt user2@host2:/path/

Current machine must have access to both host1 and host2

Batch upload files (script example)
for f in *.log; do
  scp "$f" user@host:/var/logs/
done

Common Command Templates

scp ./local.txt user@host:/remote/path/
scp user@host:/remote/file.txt ./local/
scp -r ./dir user@host:/remote/
scp -i ~/.ssh/key.pem -P 2222 ./file user@host:/dest/