linux remote file copy ----- scp

scp

Linux scp command is used to copy files and directories between Linux.
scp is a secure copy of the abbreviation, scp remote file copy is based on ssh command for secure login linux system.

scp advantages and disadvantages

scp command for a remote command to copy files in Linux, and it is similar to the cp command there, but cp only copy in the machine can not be cross-server, and scp transmission is encrypted. It may slightly affect what speed. When your server's hard disk becomes read-only read only system, using scp can help you to move out of the file. In addition, scp also very much resources, how much load the system will not improve, at this point, rsync is far less than it. Although a little faster than scp rsync will, but under the circumstances of many small files, rsync will lead to disk I / O is very high, and scp does not influence the normal use of the system.

grammar

scp	【选项】	【参数】

Parameter Description

-1: using ssh protocol version 1;
-2: using ssh protocol version 2;
-4: using IPv4;
-6: using IPv6;
-B: run in batch mode;
-C: using compressed;
-F: Specifies ssh profiles;
the -l: Specifies the bandwidth limitations;
-o: Specifies the option to use ssh;
-P: Specifies the remote host port number;
-p: keep the file was last modified, last access time and permission modes;
-q: no The copy progress;
-r: copy recursively.

Using the full syntax

1. Download the file from a remote server to a local directory

scp 用户名@目标主机IP:文件所在路径 本地主机存放路径

2. Upload a file to a remote server specified directory

scp 本地文件路径	用户名@目标主机IP:远程服务器存放路径

Simple examples

Note: The IP address of the two hosts are: 192.168.1.123,192.168.1.124
1) download files from a remote server to a local directory
using ssh protocol version 2 download test files in the / root directory on the local host 192.168.1.124 the root directory

[root@linus ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg
[root@linus ~]# scp -2 root@192.168.1.124:/root/test /root
The authenticity of host '192.168.1.124 (192.168.1.124)' can't be established.
ECDSA key fingerprint is SHA256:UPiyXj1RamlkIMDY4KO4mzUtR8cm8mCzL6b5E1YIEAY.
ECDSA key fingerprint is MD5:f2:2c:7f:88:a0:e3:1e:1c:36:aa:f7:fc:bd:76:a1:eb.
Are you sure you want to continue connecting (yes/no)? yes	#提示您确定要继续连接吗?选择yes
Warning: Permanently added '192.168.1.124' (ECDSA) to the list of known hosts.
root@192.168.1.124's password: 	#输入192.168.1.124主机上root用户的密码
test                   100%    0     0.0KB/s   00:00    #进度
[root@linus ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  test		#test文件下载到本地了

Recursively dir directory on the host 192.168.1.124 downloaded to the local root directory

[root@linus ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  test
[root@linus ~]# scp -r root@192.168.1.124:/root/dir /root
root@192.168.1.124's password: 
[root@linus ~]# ls
anaconda-ks.cfg  dir  initial-setup-ks.cfg  test	#dir目录已经被下载下来了

2) upload local files to a remote server
** no progress upload a local / root / share files to the / root directory of the remote server

[root@linus ~]# scp -q /root/share root@192.168.1.124:/root/
root@192.168.1.124's password: 
[root@linus ~]# ls		#远程服务器上查看已存在
anaconda-ks.cfg  initial-setup-ks.cfg  share  yum.sh

Recursively local / root / gx uploaded to the remote server's directory / root directory

[root@linus ~]# scp -r /root/gx/ root@192.168.1.124:/root/
root@192.168.1.124's password: 
[root@linus ~]# ls		#远程服务器上查看也已经上传成功
anaconda-ks.cfg  gx                    share  yum.sh
dir              initial-setup-ks.cfg  test
Published 14 original articles · won praise 4 · Views 522

Guess you like

Origin blog.csdn.net/qq_42534026/article/details/104147063