Latest web development tutorials

Linux scp command

Linux scp command

Linux command Daquan Linux command Daquan

Linux scp command to copy files and directories between Linux.

scp is a secure copy of the acronym, scp remote file copy is based on ssh command for secure login linux system.

grammar

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2

Simple wording:

scp [可选参数] file_source file_target 

Parameter Description:

  • -1: Forced scp command protocol ssh1
  • -2: Forced scp command protocol ssh2
  • -4: Forced scp command uses only IPv4 addressing
  • -6: Forced scp command uses only IPv6 addressing
  • -B: Use batch mode (transmission not ask transmission password or phrase)
  • -C: Allow compression. (The -C flag to ssh, thereby opening the compression)
  • -p: to retain the original file modification time, access time and access rights.
  • -q: does not display the transmission progress bar.
  • -r: recursive copy the entire directory.
  • -v: verbose mode display output. scp and ssh (1) will show the whole process of debugging information. This information is used for debugging connection, authentication, and configuration problems.
  • -c cipher: cipher to encrypt the data, this option will be passed directly to ssh.
  • -F Ssh_config: ssh specify an alternate configuration file, this parameter is directly passed to ssh.
  • -i identity_file: Key file is read from the specified file transfer used, this parameter is directly passed to ssh.
  • -l limit: limited bandwidth users can use to Kbit / s units.
  • -o ssh_option: If you are accustomed to using ssh_config (5) in the way of passing parameters,
  • -P Port: note the capital P, port is used to specify the port number of data transfer
  • -S Program: Specifies the program used to encrypt the transmission. This program must be able to understand ssh (1) options.

Examples

1, copied from local to remote

Format:

scp local_file remote_username@remote_ip:remote_folder 
或者 
scp local_file remote_username@remote_ip:remote_file 
或者 
scp local_file remote_ip:remote_folder 
或者 
scp local_file remote_ip:remote_file 

  • 1,2 designated user name, command execution need to enter a password, only the first one specifies the remote directory, file name unchanged Article 2 specifies the file name;
  • The first three or four did not specify a user name, you need to enter a user name and password command is executed, only the first three of the specified remote directory, file name unchanged Article 4 specifies the file name;

Applications:

scp /home/space/music/1.mp3 [email protected]:/home/root/others/music 
scp /home/space/music/1.mp3 [email protected]:/home/root/others/music/001.mp3 
scp /home/space/music/1.mp3 www.w3cschool.cc:/home/root/others/music 
scp /home/space/music/1.mp3 www.w3cschool.cc:/home/root/others/music/001.mp3 

Copy the directory command format:

scp -r local_folder remote_username@remote_ip:remote_folder 
或者 
scp -r local_folder remote_ip:remote_folder 
  • The first one specifies the user name, the command execution need to enter a password;
  • The first two do not specify a user name, command execution will need to enter a user name and password;

Applications:

scp -r /home/space/music/ [email protected]:/home/root/others/ 
scp -r /home/space/music/ www.w3cschool.cc:/home/root/others/ 

The above command copies the local music directory to the remote directory others.

2, copied from remote to local

Copy from remote to local, two parameters just copy from the local to the remote command to reverse the order, the following examples

Applications:

scp [email protected]:/home/root/others/music /home/space/music/1.mp3 
scp -r www.w3cschool.cc:/home/root/others/ /home/space/music/

Explanation

1. If the remote server firewall promising scp command sets the specified port, we need to use the -p parameter to set the port number of the command, the command format is as follows:

#scp命令使用端口号 4588
scp -p 4588 [email protected]:/usr/local/sin.sh /home/administrator

2. Use the scp command to ensure users have a remote server can read the file permissions, otherwise scp command is inoperable.

Linux command Daquan Linux command Daquan