Weblutions Documentation
Weblutions Main Site Contact Us Our Discord
Some pages are still pending proper formatting, if required refer to the legacy documentation website.
Knowledgebase IconKnowledgebase

Weblutions Documentation / Knowledgebase / Transfer Directories Between Ubuntu Servers

Updated

Transfer Directories Between Ubuntu Servers

By Josh M. 1 mins 3

Transferring content between two Linux servers can seem daunting if you're new to Linux. This guide will walk you through using the scp command (specifically on Ubuntu) to send files or entire directories from one Ubuntu server to another. Don’t worry, it’s simpler than you think!


Table of Contents


What is SCP (Secure Copy)?

The scp (secure copy) command in Linux is used to securely transfer files or directories between systems over SSH. It works similarly to the cp command but allows copying to or from remote machines, with all data encrypted during transfer.

Why use SCP?

While there are other tools like rsync for transferring files between servers, scp is straightforward and reliable, perfect for simple tasks. This guide keeps things beginner-friendly by focusing on scp.

How to Use SCP

To transfer content between two servers, you’ll need the SSH connection details for both machines. Let’s assume there’s "Server 1" and "Server 2", and you want to transfer content from Server 1 to Server 2.


Transferring a Single File

Run the below command on Server 1 (the source), replacing the placeholders in the command with the actual details of server 2.

scp /path/to/local.file SERVER_2_USERNAME@SERVER_2_IP:/path/to/save.file

Example

scp /var/www/html/index.html root@123.321.789.1:/var/www/html/index.html

Transferring a Directory

To transfer an entire folder and its contents, for example the entire /home folder, add the recursive flag (-r) to the command

scp -r /home SERVER_2_USERNAME@SERVER_2_IP:/home

Example

scp -r /home root@123.321.789.1:/home

What to Expect

When you run these commands, you may be prompted to confirm the server’s fingerprint and enter Server 2’s password. Once authenticated, the transfer will begin, and progress will be shown in your terminal.

And that’s it! You’ve successfully transferred files or directories between Ubuntu servers using SCP.