facebook youtube pinterest twitter reddit whatsapp instagram

Transferring files with scp In [Ubuntu]

I recently wrote a basic guide on transferring files with rsync, and I outlined some examples, while rsync is really powerful, the major problem I have with it is that it doesn't support the transfer of files from one remote host to another, it works with local to remote, and vice verse.

This is where scp overshines, secure copy (scp) relies on SSH to transfer files between hosts one a network, the good thing is it uses the same authentication and provides the same security as ssh. scp will ask for passwords or passphrases if they are needed for authentication.

Note: I would be using the simplifying my SSH connections, this way, I won't need to manually type the server I am connection to by hand, Learn how to do so in the guide below:

https://devsrealm.com/cloud-computing/ubuntu/simplifying-ssh-connections-with-a-config-file/embed

SCP is similar to rsync, the same rules apply; it requires a source (where you are copying from), and a target (where you are copying to).

Transferring a File Locally To a Remote Host

scp /home/user/testfile.txt ServerA:/backup

The above command is copying file testfile.txt from the user directory to a backup directory in ServerA.

If you do not specify a directory in the target server, it would copy to the home directory of the target server as specified in your SSH config file.

Transferring a File From Remote Host To a Local Server

This is the reverse of the above command:

scp ServerA:/backup/testfile.txt /home/user

This would copy testfile.txt from the ServerA backup directory into the user local directory.

Downloading an Entire Directory, and Its Contents

To download, and copy an entire directory with its content, you add and -r option, which does a recursive copy of the entire directory, for example:

scp -r /home/user/bookd ServerA:downloads

Since you added the -r option, it will transfer the book folder and
all of its contents into the serverA download folder, so, say the user of the ServerA is James, it would transfer the file under /home/james/downloads.

If you want the command to show you the details of what is going on, you can ass the -v option, this would show you how the command progresses as it copies multiple file, e.g:

scp -rv /home/user/bookd ServerA:downloads

For those not using SSH config, scp assumes that SSH is listening on port 22 on the remote machine, so, if your SSH port has been changed, you can add designate a different port with the -p option:

scp -P 2222 -r /home/user/books faruq@192.168.1.50:downloads

Note: The above command only applies for does not using SSH config.

Related Post(s)

  • Monitoring Multiple Log Files In RealTime With MultiTail (Ubuntu)

    Oh my... I really find scanning through the logs file time consuming, and painful. Luckily for me, I founded Multitail, which is an awesome, and powerful tool for not only browsing through several f

  • How To Find Files Using Locate in Ubuntu

    It's kind of frustrating when you are searching for a particular file, and you have no idea of how to find it, In this guide, I'll walk you through on two different ways you can find a file in your G

  • Managing MariaDB Databases (Ubuntu Server)

    In this guide, you'll learn how to manage MariaDB databases in your terminal, from connecting to the database server using the mariadb command, creating a database, removing (drop) database, and mana

  • Viewing Disk Usage in Ubuntu

    There are several ways to view disk usage in your Linux system, and that is what we would be going over in this guide... Out of the box, Linux provides us the df command, which is the standard Unix c

  • Understanding & Using Symbolic & Hard Links (Ubuntu)

    Have you ever wondered how you can create shortcuts that link to other files in Linux? Well, let me introduce you to symbolic and hard links. The two types of links in Linux are symbolic links and ha

  • Installing and Using dig in Ubuntu

    dig is an awesome utility for querying DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. In this guide, you'll learn how