Copying files over SSH (scp)
How do you copy files over SSH? Learn how to copy files from your computer to a server and how to copy files from a server to your computer on Linux. You will also learn how to copy files between two servers. We will use the SCP command for this.
The name SCP stands for Secure copy. It is a tool for securely copying files between hosts over SSH. Files are copied using the SCP protocol (the protocol has the same name), which uses encryption during transfer, making the process much safer. The protocol itself does not provide authentication; the SSH protocol is used for that. The protocol is very similar to FTP, but its advantage is that it is more widely available (many servers do not have FTP installed) and it can transfer file attributes together with the file.
Copying a file to a server using SCP
The command syntax is as follows:
scp <local_file> <remote_user>@<remote_server>:/<remote_folder>If the <remote_folder> folder is not specified, the file will be copied to the remote user's home directory. Example:
scp plik.txt [email protected]:/var/Copying a file from a server using SCP
The command syntax is as follows:
scp <remote_user>@<remote_server>:/<remote_folder>/<remote_file> <local_file>Instead of <local_file>, you can use a dot to save the remote file in the local folder under the same name. Example:
scp [email protected]:/var/plik.txt plik.txt
# or equivalently:
scp [email protected]:/var/plik.txt .Copying multiple files to a server using SCP
The command syntax is as follows:
scp <local_file_1> <local_file_2> <remote_user>@<remote_server>:/<remote_folder>As before, if the <remote_folder> folder is not specified, the file will be copied to the remote user's home directory. Example:
scp plik1.txt plik2.txt [email protected]:/var/Copying all files to a server using SCP
The command syntax is as follows:
scp * <remote_user>@<remote_server>:/<remote_folder>As before, if the <remote_folder> folder is not specified, the file will be copied to the remote user's home directory. Example:
scp * [email protected]:/var/Copying all files recursively to a server using SCP
The command syntax is as follows:
scp -r * <remote_user>@<remote_server>:/<remote_folder>The command will copy all files and folders found in the specified directory. As before, if the <remote_folder> folder is not specified, the file will be copied to the remote user's home directory. Example:
scp -r * [email protected]:/var/Copying files between servers
The command syntax is as follows:
scp <remote_user1>@<remote_server1>:/<remote_folder1> <remote_user2>@<remote_server2>:/<remote_folder2>Example:
scp -r [email protected]:/var/ [email protected]:/var/Comments (0)
No comments yet.
Add a comment
Comments are published after moderation. Your e-mail address stays private.