How to Transfer Files using SCP Command in Ubuntu Linux

This article describes steps one can take to transfer files via SCP remotely in Ubuntu Linux.

SCP (secure copy) is a command-line utility that allows you to securely copy files and directories between two locations, either remotely or locally on the same host.

If you ever needed to transfer files quickly between two Ubuntu servers, the best way to do it is via SSH using Secure Copy (SCP).

SCP uses SSH encryption and authentication to securely transfer files between servers quickly and easily. 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

To transfer a file to a remote server from the local server you’re currently logged into, run the example commands below.

scp file_to_transfer.txt root@remotehost.com:/directory_to_drop_file/location/

The commands above copy a local file from the local server and transfer it to a remote server via the remote server’s hostname or IP address and drop it into the directory location specified.

How to transfer files from a remote host via SCP in Ubuntu Linux

To transfer files from a remote host to a local server, you use the example commands below. 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 root@remotehost.com:/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. 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!

Conclusion:

This post showed you how to use SCP to transfer files between two networked systems. If you find any error above or have something to add, please the comment form below.