Navigating: Home » Cloud Computing » Ubuntu » Transferring files with scp In [Ubuntu] Transferring files with scp In [Ubuntu] Posted on June 17, 2020June 18, 2020 by devsrealm 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: Simplifying SSH Connections With a Config File 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 firstname.lastname@example.org:downloads Note: The above command only applies for does not using SSH config.