The SCP is a secure copy shorthand for remote copy of files under Linux, and a similar command has CP, but the CP is only copied on the local computer, not across servers, and the SCP transmission is encrypted. may have a slight impact on speed. When your server hard drive becomes read only system, the SCP can help you move the files out. In addition, the SCP is very not a resource, does not increase the number of system load, at this point, rsync is far less than it. While rsync is faster than SCP, rsync can cause hard disk I/O to be very high when small files are large, and the SCP does not affect the normal use of the system.
1. Command format:
SCP [parameters] [Original path] [Target path]
2. Command function:
The SCP is a secure copy abbreviation, and the SCP is a secure remote file Copy command under the Linux system based on SSH login. The SCP commands for Linux can replicate files and directories between Linux servers.
3. Command parameters:
-1 Mandatory SCP command use protocol SSH1
-2 Mandatory SCP command use protocol SSH2
-4 Force the SCP command to use only IPV4 addressing
-6 Force the SCP command to use only IPV6 addressing
-B Use Batch mode (transfer password or phrase not queried during transmission)
-C allows compression. (Pass the-c flag to SSH to turn on the compression feature)
-P preserves the modification time, access time, and access rights of the original file.
-Q does not display the transport progress bar.
-R recursively copies the entire directory.
-V Displays the output in verbose mode. SCP and SSH (1) will display debugging information for the entire process. This information is used to debug connections, verify, and configure problems.
-C cipher encrypts the data transfer in cipher, this option is passed directly to SSH.
-F ssh_config Specifies an alternate SSH configuration file, which is passed directly to SSH.
-I identity_file the key file used to read the transfer from the specified file, which is passed directly to SSH.
-L limit limits the bandwidth that the user can use, in kbit/s units.
If the-O ssh_option is accustomed to using parameter passing in Ssh_config (5),
-P Port Note is uppercase P, port is the port number used to specify the data transfer
-S program specifies the programs to use when encrypting the transmission. This program must be able to understand the options for SSH (1).
4. Use instance:
An overview of the actual application of the SCP command:
To replicate from a local server to a remote server:
(1) Copy files:
Command format:
SCP Local_file Remote_username@remote_ip:remote_folder
Or
SCP Local_file Remote_username@remote_ip:remote_file
Or
SCP Local_file Remote_ip:remote_folder
Or
SCP Local_file Remote_ip:remote_file
1th, 2 specified the user name, the command needs to enter the user password, 1th only specified a remote directory, file name unchanged, 2nd specified the filename
3rd, 4 did not specify the user name, the command needs to enter the user name and password, 3rd only specified a remote directory, the file name unchanged, the 4th specified the filename
(2) Copy directory:
Command format:
Scp-r Local_folder Remote_username@remote_ip:remote_folder
Or
Scp-r Local_folder Remote_ip:remote_folder
The 1th specifies the user name, the command needs to enter the user password after execution;
The 2nd does not specify the user name, the command needs to enter the user name and password after execution;
To copy from a remote server to a local server:
The SCP command, which is replicated from remote to local, is identical to the command above, as long as the 2-parameter interchange order is made from the local copy to the remote command.
Example 1: Copying files from a distance to a local directory
Command:
SCP root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz/opt/soft/
Output:
BSH Code
[Root@localhost ~]# cd/opt/soft/
[Root@localhost soft]# LL
Total 80072
Drwxr-xr-x root root 4096 09-21 18:40 fms3.5
Drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5
Drwxr-xr-x root root 4096 10-30 17:15 jdk1.6.0_16
Drwxr-xr-x root root 4096 09-17 19:27 Jdk1.6.0_16.bak
-rwxr-xr-x 1 root root 81871260 2009-12-21 Jdk-6u16-linux-x64.bin
DRWXRWXRWX 2 root root 4096 09-21 01:16 MySQL
Drwxr-xr-x 3 root root 4096 09-21 18:40 setup_file
Drwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32
Drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0
[Root@localhost soft]# SCP root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz/opt/soft/
root@192.168.120.204 ' s Password:
nginx-0.5.38.tar.gz 100% 479KB 478.7kb/s 00:00
[Root@localhost soft]# LL
Total 80556
Drwxr-xr-x root root 4096 09-21 18:40 fms3.5
Drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5
Drwxr-xr-x root root 4096 10-30 17:15 jdk1.6.0_16
Drwxr-xr-x root root 4096 09-17 19:27 Jdk1.6.0_16.bak
-rwxr-xr-x 1 root root 81871260 2009-12-21 Jdk-6u16-linux-x64.bin
DRWXRWXRWX 2 root root 4096 09-21 01:16 MySQL
-rw-r--r--1 root root 490220 03-15 09:11 nginx-0.5.38.tar.gz
Drwxr-xr-x 3 root root 4096 09-21 18:40 setup_file
Drwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32
Drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0
[Root@localhost soft]#
Description
Download nginx-0.5.38.tar.gz files from the/opt/soft/directory on the 192.168.120.204 machine to the local/opt/soft/directory
Example 2: Copying from a distance to a local
Command:
Scp-r root@192.168.120.204:/opt/soft/mongodb/opt/soft/
Output:
BSH Code
[Root@localhost soft]# LL
Total 80556
Drwxr-xr-x root root 4096 09-21 18:40 fms3.5
Drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5
Drwxr-xr-x root root 4096 10-30 17:15 jdk1.6.0_16
Drwxr-xr-x root root 4096 09-17 19:27 Jdk1.6.0_16.bak
-rwxr-xr-x 1 root root 81871260 2009-12-21 Jdk-6u16-linux-x64.bin
DRWXRWXRWX 2 root root 4096 09-21 01:16 MySQL
-rw-r--r--1 root root 490220 03-15 09:11 nginx-0.5.38.tar.gz
Drwxr-xr-x 3 root root 4096 09-21 18:40 setup_file
Drwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32
Drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0
[Root@localhost soft]# scp-r root@192.168.120.204:/opt/soft/mongodb/opt/soft/
root@192.168.120.204 ' s Password:
Mongodb-linux-i686-static-1.8.5.tgz 100% 28MB 28.3mb/s 00:01
README 100% 731 0.7kb/s 00:00
Third-party-notices 100% 7866 7.7kb/s 00:00
Mongorestore 100% 7753KB 7.6mb/s 00:00
Mongod 100% 7760KB 7.6mb/s 00:01
Mongoexport 100% 7744KB 7.6mb/s 00:00
Bsondump 100% 7737KB 7.6mb/s 00:00
Mongofiles 100% 7748KB 7.6mb/s 00:01
Mongostat 100% 7808KB 7.6mb/s 00:00
MONGOs 100% 5262KB 5.1mb/s 00:01
MONGO 100% 3707KB 3.6mb/s 00:00
Mongoimport 100% 7754KB 7.6mb/s 00:00
Mongodump 100% 7773KB 7.6mb/s 00:00
gnu-agpl-3.0 100% 34KB 33.7kb/s 00:00
[Root@localhost soft]# LL
Total 80560
Drwxr-xr-x root root 4096 09-21 18:40 fms3.5
Drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5
Drwxr-xr-x root root 4096 10-30 17:15 jdk1.6.0_16
Drwxr-xr-x root root 4096 09-17 19:27 Jdk1.6.0_16.bak
-rwxr-xr-x 1 root root 81871260 2009-12-21 Jdk-6u16-linux-x64.bin
Drwxr-xr-x 3 root root 4096 03-15 09:18 MongoDB
DRWXRWXRWX 2 root root 4096 09-21 01:16 MySQL
-rw-r--r--1 root root 490220 03-15 09:11 nginx-0.5.38.tar.gz
Drwxr-xr-x 3 root root 4096 09-21 18:40 setup_file
Drwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32
Drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0
[Root@localhost soft]#
Description
Download the MongoDB directory to the local/opt/soft/directory from the/opt/soft/on the 192.168.120.204 machine.
Example 3: Uploading local files to the remote machine specified directory
Command:
Scp/opt/soft/nginx-0.5.38.tar.gz Root@192.168.120.204:/opt/soft/scptest
Output:
BSH Code
Target directory of Target machine before uploading:
[Root@localhost soft]# CD scptest/
[Root@localhost scptest]# LL
Total 0
[Root@localhost scptest]# LL
Local Machine upload:
[Root@localhost soft]# scp/opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest
root@192.168.120.204 ' s Password:
nginx-0.5.38.tar.gz 100% 479KB 478.7kb/s 00:00
[Root@localhost soft]#
Target directory of Target machine after uploading:
[Root@localhost scptest]# LL
Total 484
-rw-r--r--1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz
[Root@localhost scptest]#
Description
Copy the files from the local opt/soft/directory nginx-0.5.38.tar.gz to the Opt/soft/scptest directory of the remote machine 192.168.120.204
Example 4: Upload local directory to remote machine specified directory
Command:
Scp-r/opt/soft/mongodb Root@192.168.120.204:/opt/soft/scptest
Output:
BSH Code
Target directory of Target machine before uploading:
[Root@localhost ~]# cd/opt/soft/scptest/
[Root@localhost scptest]# LL
Total 484
-rw-r--r--1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz
[Root@localhost scptest]#
Local Machine upload:
[Root@localhost ~]# scp-r/opt/soft/mongodb root@192.168.120.204:/opt/soft/scptest
root@192.168.120.204 ' s Password:
Mongodb-linux-i686-static-1.8.5.tgz 100% 28MB 28.3mb/s 00:01
README 100% 731 0.7kb/s 00:00
Third-party-notices 100% 7866 7.7kb/s 00:00
Mongorestore 100% 7753KB 7.6mb/s 00:00
Mongod 100% 7760KB 7.6mb/s 00:01
Mongoexport 100% 7744KB 7.6mb/s 00:00
Bsondump 100% 7737KB 7.6mb/s 00:00
Mongofiles 100% 7748KB 7.6mb/s 00:00
Mongostat 100% 7808KB 7.6mb/s 00:01
MONGOs 100% 5262KB 5.1mb/s 00:00
MONGO 100% 3707KB 3.6mb/s 00:00
Mongoimport 100% 7754KB 7.6mb/s 00:01
Mongodump 100% 7773KB 7.6mb/s 00:00
gnu-agpl-3.0 100% 34KB 33.7kb/s 00:00
[Root@localhost ~]#
Target directory of Target machine after uploading:
[Root@localhost scptest]# LL
Total 488
Drwxr-xr-x 3 root root 4096 03-15 09:33 MongoDB
-rw-r--r--1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz
[Root@localhost scptest]#
Description:
upload the local directory/opt/soft/mongodb to the/opt/soft/scptest directory on the remote machine 192.168.120.204