scp 命令的使用, 上传和下载文件
在使用 ssh 连接 linux 服务器时,如果需要上传和下载文件,除了使用 FTP 软件外,还可以直接使用 scp 命令来进行操作
下载文件
格式:scp 用户名@远程服务器ip:文件路径 目标路径
scp user@server_ip:/file_path to_path
例子:
将 172.12.121.87 服务器 /home 目录下的 test.txt 文件,下载到本地 /home 目录下
scp root@172.12.121.87:/home/test.txt /home
如果需要指定端口号,则使用 -P 参数,(注意:大写字母 P)
scp -P 22 root@172.12.121.87:/home/test.txt /home
上传文件
是下载的逆过程
格式: scp 需要上传的文件路径 用户名@远程服务器ip:文件路径
scp local_file_path root@server_ip:/file_path
例子:
scp /home/test.txt root@172.12.121.87:/home
同理,如果需要指定端口号,还是使用 -P 参数,(注意:大写字母 P)
scp -P 22 /home/test.txt root@172.12.121.87:/home
参考
SCP Linux – Securely Copy Files Using SCP examples
scp command in Linux with Examples