scp命令用于Windows和Linux之间复制文件

简述

Linux scp 命令用于 Linux 之间复制文件和目录。
scp 是 secure copy 的缩写, scp 是 linux 系统下基于 ssh 登陆进行安全的远程文件拷贝命令。
scp 是加密的,rcp 是不加密的,scp 是 rcp 的加强版。

Windows和Linux之间复制文件

Windows本身不支持ssh协议,因此要互传文件,需在Windows系统上安装ssh for Windows的软件
如winsshd,可以使Windows系统支持ssh协议;或者用Windows自带的openssh
流程:右键左下角“开始”->“设置”->“应用”->“可选功能”->进行操作
如下图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

使用

Windows下是在shift+鼠标右键进行powershell下键入命令
linux是在terminal终端下键入命令:Ctrl+Alt+T

scp [可选参数] file_source file_target 

基本参数:
-f:表示复制文件
-r:表示递归文件夹
参数可参考:链接: https://www.runoob.com/linux/linux-comm-scp.html

示例

从本地复制到远程
复制文件
本地文件->远程文件夹
scp local_file remote_username@remote_ip:remote_folder 
本地文件->远程文件
scp local_file remote_username@remote_ip:remote_file 

输入完,敲回车,需输入远程密码

复制文件夹
本地文件夹->远程文件夹
scp -r local_folder remote_username@remote_ip:remote_folder 

输入完,敲回车,需输入远程密码

从远程复制到本地
复制文件
远程文件->本地文件
scp  remote_username@remote_ip:remote_file local_file

输入完,敲回车,需输入远程密码

复制文件夹
远程文件夹->本地文件夹
scp -r  remote_username@remote_ip:remote_folder local_folder

输入完,敲回车,需输入远程密码

在Linux下(从Linux复制到Windows)
复制文件
scp /home/hh/Desktop/test.txt hh@192.168.123.123:/C:/Users/hh/Desktop/newFolder
或
scp /home/hh/Desktop/test.txt hh@192.168.123.123:/C:/Users/hh/Desktop/newFolder/test.txt

输入完,敲回车,需输入远程密码
hh为Windows用户名,192.168.123.123为Windows的ip,/C:/Users/hh/Desktop/newFolder(/C:/Users/hh/Desktop/newFolder/test.txt)为想要将文件复制到Windows的哪个文件夹(文件)

复制文件夹
本地文件夹->远程文件夹
scp -r /home/hh/Desktop/ hh@192.168.123.123:/C:/Users/hh/Desktop/newFolder

输入完,敲回车,需输入远程密码

在Windows下(从Windows复制到Linux)
复制文件
scp C:/Users/hh/Desktop/newFolder/test.txt hh@192.168.123.123:/home/hh/Desktop/
或
scp C:/Users/hh/Desktop/newFolder/test.txt hh@192.168.123.123:/home/hh/Desktop/test.txt

hh为Linux用户名,192.168.123.123为Linux的ip,/home/hh/Desktop(/home/hh/Desktop/test.txt)为想要将文件复制到Linux的哪个文件夹(文件)

复制文件夹
scp -r C:/Users/hh/Desktop/newFolder hh@192.168.123.123:/home/hh/Desktop
在Linux下(从Windows复制到Linux)
复制文件
scp hh@192.168.123.123:C:/Users/hh/Desktop/newFolder/test.txt 
/home/hh/Desktop/
或
scp hh@192.168.123.123:C:/Users/hh/Desktop/newFolder/test.txt 
/home/hh/Desktop/test.txt

hh为Windows用户名,192.168.123.123为Windows的ip,/home/hh/Desktop(/home/hh/Desktop/test.txt)为想要将文件复制到Linux的哪个文件夹(文件)

复制文件夹
scp -r hh@192.168.123.123:C:/Users/hh/Desktop/newFolder/
/home/hh/Desktop/
在Windows下(从Linux复制到Windows)
复制文件
scp hh@192.168.123.123:/home/hh/Desktop/test.txt
C:/Users/hh/Desktop/newFolder/
或
scp hh@192.168.123.123:/home/hh/Desktop/test.txt
C:/Users/hh/Desktop/newFolder/test.txt 

hh为Linux用户名,192.168.123.123为Linux的ip,C:/Users/hh/Desktop/newFolder(C:/Users/hh/Desktop/newFolder/test.txt )为想要将文件复制到Windows的哪个文件夹(文件)

复制文件夹
scp hh@192.168.123.123:/home/hh/Desktop/
C:/Users/hh/Desktop/newFolder/

猜你喜欢

转载自blog.csdn.net/MrHHHHHH/article/details/132380067
今日推荐