This article describes the steps to transfer files via SCP remotely in Ubuntu Linux.
SCP (secure copy) is a command-line utility that securely copies files and directories between two locations, either remotely or locally, on the same host.
If you ever need to transfer files quickly between two Ubuntu servers, the best way is via SSH using Secure Copy (SCP).
SCP uses SSH encryption and authentication to quickly and securely transfer files between servers. Secure copy is a means of securely transferring files and folders between two locations.
How to transfer files to a remote host via SCP in Ubuntu Linux
Run the example commands below to transfer a file to a remote server from the local server you’re currently logged into.
scp file_to_transfer.txt email@example.com:/directory_to_drop_file/location/
The commands above copy a local file from the local server, transfer it to a remote server via the server’s hostname or IP address and drop it into the specified directory location.
How to transfer files from a remote host via SCP in Ubuntu Linux
You use the example commands below to transfer files from a remote host to a local server. Let’s say you want to copy your entire website content into a zipped folder called website_content.zip.
You run the commands below to copy the content from the remote server to the local host.
scp firstname.lastname@example.org:/directory/website_content.zip /path_to_store_content/www/html/website_content.zip
Doing the above will copy the remote content to the local host securely. Next, replace remotehost.com with the hostname or the IP address of the remote server. Also, replace the root with the actual admin account of the server.
For some reason, if the SSH default port is changed from 22, you may have to specify the new port when using the commands above. The example command is shown below.
scp -P 2221 local_file.txt username@remotehost:/directory/location/
Do the same when copying files from the remote host to the local server.
That should do it!
This post showed you how to use SCP to transfer files between two networked systems. Suppose you find any error above or have something to add, please use the comment form below.