scp默认情况下使用ssh的22端口进行传输
假设有一个远程文件路径/root/file.txt
,SSH端口是22,如果我们要将这个文件下载到本地/local/test.txt
下,有以下两种方法:
scp -P 22 root@VPSIP:/root/file.txt /local/test.txt
若针对目录:
scp -P 22 root@VPSIP:/root /local
scp -P 22 -i /local/local.pem root@VPSIP:/root /local
类似上面
scp -r -P 22 /local/test.txt root@VPSIP:/root/file.txt
上传多文件:
scp foo.txt bar.txt username@remotehost:/path/directory/
压缩上传(加快上传速度):
scp -vrC ~/Downloads root@192.168.1.3:/root/Downloads
限制上传速度:
scp -vrC -l 400 ~/Downloads root@192.168.1.3:/root/Downloads #限速400K
保存本地上传文件的属性:
scp -C -p ~/test.txt root@192.168.1.3:/some/path/test.txt
若是目录:
scp -r -P 22 /local root@VPSIP:/root
scp -r -P 22 /local/test.txt root@VPSIP:/root/file.txt
如果,想要使用其他用户的ssh配置信息传输:
scp -vC -F /home/user/my_ssh_config ~/test.txt root@192.168.1.3:/some/path/test.txt
scp user1@remotehost1:/some/remote/dir/foobar.txt user2@remotehost2:/some/remote/dir/
最后,如果想显示传输细节,可以附加-v
参数
参考:
12个scp传输文件的命令栗子