It looks like you're new here. If you want to get involved, click one of these buttons!Sign In Register
It looks like you're new here. If you want to get involved, click one of these buttons!
SCP(Secure Copy) is an easy way to transfer files between two servers that uses SSH so it provides the same level of security. This method requires access to both servers, so you won't be able to transfer files without having access to the remote servers.
Below is the syntax for the command to copy local data to another server
scp test_file.txt [email protected]_server_IP:/remote/directory
Explanation of syntax is below:
scp - main command;
test_file.txt - a file that is being transferred;
remote_server_username - the user that you will be using to connect to a remote server, for example, root;
remote_server_IP - the IP of a remote server;
/remote/directory - this is the directory path that a file will be copied to. Make sure it is created on the remote server.
The example s below:
scp 1G.test [email protected] /home
The example shows how a file "1G.test" is being copied to a remote server's /home folder. Once the command is executed, you will be asked to confirm if you want to continue the connection.
Are you sure you want to continue connecting (yes/no)?
Enter "yes" and you will be prompted for a remote server password. As soon as you enter it, the file transfer begins and you will be able to see the progress bar as well.
This is basically the vice versa of the previous command, you can check the syntax below:
scp [email protected]_server_IP:/remote/file.txt /local/directory
The command is simple, just remember that now you are declaring the remote server's file path and local server's directory to copy.
If you have more than two servers, you can use scp command to copy files from one remote server to another remote server, it will help you to manage and move files without actually connecting to each server every time manually. The syntax is below:
This example will copy the file "/files/file.txt", from server1 to a folder "/files" on server2. Also, you will need login details to both servers.
You can copy multiple files by simply declaring a few of them:
scp file1.txt file2.txt archive.gzip [email protected]_server_IP:/home
The example above shows how to multiple files to a remote server.
You can copy a full directory as well with option -r, here is the example:
scp -r /home/backups/backup1 [email protected]_server_IP:/home
The example above shows how to use option -r, to copy the whole folder "/home/backups/backup1" to a remote server.
SCP command works with custom SSH port as well, the option for that is -P, for example:
scp -P 1234 file1.txt [email protected]_server_IP:/home
The example above allows transferring the file to a remote server that uses custom SSH port 1234 with an option -P. By default, the command uses default SSH port 22.
Note. The SCP works on Windows as well, you will just need some SSH client.
More information on SCP documentation can be found here.