When working with remote servers, sometimes you need to move files between your local machine and the server. One of the most popular tools is the Secure Copy Protocol (SCP), a secure and efficient way to transfer files between systems. This tutorial will discuss using SCP to copy files to a remote server.
We will be using the server name codetryout in all examples. Make sure to replace it with your server hostname or IP address.
Copying Files with SCP
To copy a file from your local machine to a remote server, use the following command:
scp /path/to/local/file devops@codetryout:/path/to/remote/directory
This command will copy the file located at /path/to/local/file to the remote server at remote under the specified directory /path/to/remote/directory`. Make sure to replace the username devops with your username on the remote server.
To copy a file from a remote server to your local machine, use the following command:
scp devops@codetryout:/path/to/remote/file /path/to/local/directory
This command will copy the file located at /path/to/remote/file on the remote server to the specified directory /path/to/local/directory on your local machine.
Copying Directories with SCP
To copy a directory and its contents from your local machine to a remote server, use the following command:
scp -r /path/to/local/directory devops@codetryout:/path/to/remote/directory
This command will copy the directory located at /path/to/local/directory to the remote server under the specified directory /path/to/remote/directory. Again, replace the username with your actual username on the remote server.
To copy a directory and its contents from a remote server to your local machine, use the following command:
scp -r devops@codetryout:/path/to/remote/directory /path/to/local/directory
This command will copy the directory located at /path/to/remote/directory on the remote server to the specified directory /path/to/local/directory on your local machine.
Conclusion
SCP is a powerful tool for copying files and directories between systems. You can quickly and securely move files between your local machine and a remote server with just a few simple commands. By mastering SCP, you can streamline your workflow and work more efficiently with remote servers.