aarontian
65 天前
```bash
# 方法 1:直接用 scp ,通过本机中转,效率较低
scp remote1:/path/to/source remote2:/path/to/destination
# 方法 2:在源服务器上使用 scp
ssh remote1 "scp /path/to/source remote2:/path/to/destination"
# 方法 3:使用 rsync 的方式
rsync -av -e ssh /path/to/source remote2:/path/to/destination
# 方法 4:使用 netcat 在服务器之间建立直接连接
# 在目标服务器上:
nc -l -p 1234 > destination_file
# 在源服务器上:
cat source_file | nc remote2 1234
# 方法 5:禁用本地中转,尝试建立直接连接,仅适用较新版本的 OpenSSH ( 8.0+)
scp -3 remote1:/path/to/source remote2:/path/to/destination
```
作为最佳实践,我建议:
1. 对于大文件传输,优先考虑使用直接传输的方式
2. 考虑使用 rsync 替代 scp ,因为 rsync 提供更多功能(如断点续传、增量同步等)
3. 在生产环境中,注意评估网络带宽和安全性要求
以上截取自 claude 的回答,未经验证