The scp
command is used to securely copy files and directories between Linux and Unix operating systems. It employs the SSH protocol to encrypt and authenticate data transfers, ensuring the security and integrity of the data. Windows 10 and later versions also include this command, making it easy to transfer large files from Windows to Linux systems.
The syntax for the scp
command is as follows:
|
|
Here, [options]
is optional, and the following parameters can be used with the scp
command:
-P
: Specify the SSH port number.-r
: Recursively copy an entire directory.-v
: Enable verbose mode to display the progress of thescp
command.-C
: Enable compression to reduce the size of the data being transferred.-p
: Preserve file modification times, access times, and permissions.
[source file or directory]
specifies the local path of the file or directory to be copied. If you want to copy multiple files, you can use wildcards to match the relevant files.
[destination file or directory]
specifies the path on the target host (which can be a local or remote path) in the format [user@]host:[/path/to/]file
. If the user is omitted, the current user is used by default. If the remote path is omitted, the default is the current user’s home directory.
Here are some examples of using the scp
command:
- Copying a file from local to remote server:
|
|
- Copying a file from remote server to local:
|
|
- Copying an entire directory from local to remote server:
|
|
- Copying an entire directory from remote server to local:
|
|
Note that the scp
command requires an established SSH connection before execution. If you have set up SSH key authentication between the local and remote hosts, you can avoid entering a password each time. For more information, please refer to the relevant documentation or type man scp
in the terminal to view the manual page for the scp
command.