Copying Files from Local to Remote Server with SCP on Ubuntu 22.04

SCP (Secure Copy Protocol) is a command that securely transfers files from a local to a remote server through SSH. During copying files, SCP keeps your data safe and secure through encryption. Moreover, you can move multiple files from a local to a remote server.

Through this guide, we will explore how to copy files from a local to a remote server using SCP Command on Linux (Ubuntu 22.04).

Copying Files from Local to Remote Server with scp on Ubuntu 22.04?

You can securely copy or transfer files from a local to a remote server through SCP on Ubuntu 22.04 using the following guide.

Check SSH Status

Before using SCP to copy files to a remote server, ensure SSH is active on your Ubuntu system. You can check the status of SSH using the following command:

sudo systemctl status ssh
sudo systemctl status ssh

The status command will display the active or inactive status of the SSH service on your screen, along with information about the active port (i.e., port 22 or 2222) of a remote server.

Transfer Single File

To transfer a file from your local to a remote server via SCP, execute the command:

scp -P 2222 ~/Documents/backup-folder/file.txt [email protected]:~/Downloads
scp -P 2222 ~/Documents/backup-folder/file.txt techpub@127.0.0.1:~/Downloads

A brief explanation of the above command is:

  • -P 2222: A dedicated port for the remote server.
  • ~/Documents/backup-folder/file.txt: Absolute path of the file on your local system.
  • [email protected]: Remote server 
  • :~/Downloads: Path on the remote server to copy files.

In short, this command will transfer “file.txt” from the local to the remote directory, such as /Downloads.

Transfer Two or More Files

The SCP also allows you to transfer two or more files. First, navigate to the directory containing the files you want to copy:

cd ~/Documents/backup-folder/

Now, run the command using the following syntax to copy files to the remote directory:

scp -P 2222 file.txt image.jpg [email protected]:~/Downloads
scp -P 2222 file.txt image.jpg techpub@127.0.0.1:~/Downloads

The list of copied files will be displayed on your terminal screen after the successful execution of the command.

Copy Files From Different Paths

You can also copy files from different paths to the remote directory through the command:

scp -P 2222 ~/Documents/backup-folder/file.txt ~/Documents/sample.doc [email protected]:~/Downloads
scp -P 2222 ~/Documents/backup-folder/file.txt ~/Documents/sample.doc techpub@127.0.0.1:~/Downloads

Copy an Entire Directory

To copy the entire directory, such as backup-folder, from your local machine to the remote directory, add the “-r” option with the SCP command: 

scp -r -P 2222 ~/Documents/backup-folder [email protected]:~/Downloads
scp -r -P 2222 ~/Documents/backup-folder techpub@127.0.0.1:~/Downloads

The above command will copy all the contents of the backup-folder to the ~/Downloads directory on the remote server.

Verify Files After Transfer

To confirm whether the file(s) has been copied to the remote server, run the command:

ssh [email protected] -p 2222 "ls -l ~/Downloads/"
ssh techpub@127.0.0.1 -p 2222 "ls -l ~/Downloads/"

The list of copied files on your screen indicates that you have successfully transferred files with the scp command on Ubuntu 22.04.

Conclusion

The SCP command facilitates the secure transfer of files from a local to a remote server. Its syntax, “scp [options] [destination],” can be executed within the Ubuntu terminal. This post provided a comprehensive guide on copying files from local to remote servers with the scp command on the Ubuntu 22.04 system.

We appreciate your presence at Ultahost! Your trust is invaluable to us. Discover seamless VPS hosting solutions with Ultahost, where reliability converges with innovation. Elevate your online presence with us – because your success is our top priority!

FAQ

What is SCP?
What is SCP used for in the Ubuntu system?
Can I use SCP to transfer file(s) to a remote server?
How do I check if SCP is installed on my Ubuntu 22.04 system?

Related Post

How to Install Tor on Ubuntu

Ubuntu, a popular Linux distribution, provides a robust...

How to Connect to SQLite from the Command Lin

SQLite is a lightweight, self-contained, and serverless...

Exploring the installation process of MongoDB

MongoDB, the popular NoSQL database, offers a powerful ...

How to Setup Apache Virtual Hosts on Ubuntu 2

Apache Virtual Hosts offer a powerful way to manage mul...

How to Install Deb Files / Packages on Ubuntu

The .deb packages are the standard format for installin...

How to Install Logwatch on Ubuntu

As a Ubuntu user, managing system logs can be a dauntin...

Leave a Comment