• news
  • pics
  • linux
  • windows
  • proxmox
  • game
  • news
  • pics
  • linux
  • windows
  • proxmox
  • game
Home
linux

How to Securely Transfer Files Between Servers with scp

If you run a live or home server, moving files between local machines or two remote machines is a basic requirement. There are many ways to achieve that. In this article, we talk about scp (secure copy command) that encrypts the transferred file and password so no one can snoop. With scp you don’t have to start an FTP session or log into the system.

The scp tool relies on SSH (Secure Shell) to transfer files, so all you need is the username and password for the source and target systems. Another advantage is that with SCP you can move files between two remote servers, from your local machine in addition to transferring data between local and remote machines. In that case you need usernames and passwords for both servers. Unlike Rsync, you don’t have to log into any of the servers to transfer data from one machine to another.

This tutorial is aimed at new Linux users, so I will keep things as simple as possible. Let’s get started.

Copy a single file from the local machine to a remote machine:

The scp command needs a source and destination to copy files from one location to another location. This is the pattern that we use:

scp localmachine/path_to_the_file [email protected]_ip:/path_to_remote_directory

In the following example I am copying a local file from my macOS system to my Linux server (Mac OS, being a UNIX operating system has native support for all UNIX/Linux tools).

scp /Volumes/MacDrive/Distros/fedora.iso 
[email protected]:/media/prim_5/media_server/

Here, ‘swapnil’ is the user on the server and 10.0.0.75 is the server IP. It will ask you to provide the password for that user, and then copy the file securely.

I can do the same from my local Linux machine:

scp /home/swapnil/Downloads/fedora.iso [email protected]:/media/prim_5/media_server/

If you are running Windows 10, then you can use Ubuntu bash on Windows to copy files from the Windows system to Linux server:

scp /mnt/c/Users/swapnil/Downloads/fedora.iso [email protected]:/media/prim_5/
  media_server/

Copy a local directory to a remote server:

If you want to copy the entire local directory to the server, then you can add the -r flag to the command:

scp -r localmachine/path_to_the_directory [email protected]_ip:/path_to_remote_directory/

Make sure that the source directory doesn’t have a forward slash at the end of the path, at the same time the destination path *must* have a forward slash.

Copy all files in a local directory to a remote directory

What if you only want to copy all the files inside a local directory to a remote directory? It’s simply, just add a forward slash and * at the end of source directory and give the path of destination directory. Don’t forget to add the -r flag to the command:

scp -r localmachine/path_to_the_directory/* [email protected]_ip:/path_to_remote_directory/

Copying files from remote server to local machine

If you want to make a copy of a single file, a directory or all files on the server to the local machine, just follow the same example above, just exchange the place of source and destination.

Copy a single file:

scp [email protected]_ip:/path_to_remote_directory local_machine/path_to_the_file 

Copy a remote directory to a local machine:

scp -r [email protected]_ip:/path_to_remote_directory local-machine/path_to_the_directory/

Make sure that the source directory doesn’t have a forward slash at the end of the path, at the same time the destination path *must* have a forward slash.

Copy all files in a remote directory to a local directory:

scp -r [email protected]_ip:/path_to_remote_directory/* local-machine/path_to_the_directory/ 

Copy files from one directory of the same server to another directory securely from local machine

Usually I ssh into that machine and then use rsync command to perform the job, but with SCP, I can do it easily without having to log into the remote server.

Copy a single file:

scp [email protected]_ip:/path_to_the_remote_file [email protected]_ip:/
  path_to_destination_directory/

Copy a directory from one location on remote server to different location on the same server:

scp [email protected]_ip:/path_to_the_remote_file [email protected]_ip:/
  path_to_destination_directory/

Copy all files in a remote directory to a local directory

scp -r [email protected]_ip:/path_to_source_directory/* [email protected]_ip:/
  path_to_the_destination_directory/ 

Copy files from one remote server to another remote server from a local machine

Currently I have to ssh into one server in order to use rsync command to copy files to another server. I can use SCP command to move files between two remote servers:

Usually I ssh into that machine and then use rsync command to perform the job, but with SCP, I can do it easily without having to log into the remote server.

Copy a single file:

scp [email protected]_ip:/path_to_the_remote_file [email protected]_ip:/
  path_to_destination_directory/

Copy a directory from one location on a remote server to different location on the same server:

scp [email protected]_ip:/path_to_the_remote_file [email protected]_ip:/
  path_to_destination_directory/

Copy all files in a remote directory to a local directory

scp -r [email protected]_ip:/path_to_source_directory/* [email protected]_ip:/
  path_to_the_destination_directory/ 
Previous article Understanding Linux File Permissions
Next article Cos不知火,取个什么标题好呢( •̆ ᵕ •̆ )

therock

17 Comments

  1. keto pork chops
    July 8, 2021 at 12:54 am

    keto bhb reviews

  2. foods to eat on a keto diet
    July 7, 2021 at 2:34 pm

    effects of keto diet

  3. keto diet principles
    July 7, 2021 at 12:02 am

    keto diet shopping list for beginners

  4. new free dating site in usa
    June 26, 2021 at 5:25 am

    baltimore sexual dating free phone lines

  5. current free dating site in australia
    June 25, 2021 at 11:10 am

    free online dating for seniors

  6. free online best dating sites
    June 24, 2021 at 7:30 pm

    free pics of women dating in my area

  7. farmers only free dating site
    June 23, 2021 at 11:33 pm

    free online dating sites christians

  8. dating sites in germany free
    June 2, 2021 at 5:40 pm

    free fuck me dating

  9. free naked dating sites
    June 2, 2021 at 11:49 am

    dating profile search free

  10. free naked dating
    June 2, 2021 at 2:09 am

    absolutely free dating sites no fees ever

  11. free dating online
    June 1, 2021 at 11:54 pm

    stop dating the church free download

  12. free hotline dating numbers
    May 27, 2021 at 1:48 pm

    free over sixties dating

  13. free dating sites scotland
    May 26, 2021 at 11:24 pm

    asian dating uk free

  14. what are good free online dating sites
    May 20, 2021 at 11:33 pm

    free dating sites reviews

  15. free japan dating sites
    May 20, 2021 at 5:42 pm

    free shemale dating uk

  16. completely free dating sites no subscription
    May 19, 2021 at 8:53 pm

    download free dating sim games

  17. Alternative tinder
    May 16, 2021 at 11:28 am

    Alternative tinder

    How to Securely Transfer Files Between Servers with scp – rock funs

Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Categories
  • game
  • linux
  • news
  • pics
  • proxmox
  • windows
Recent Posts
  • proxmox7.3直通显卡
  • Proxmox VE 直通显卡方案及解决N卡Code43
  • Linux系统出现:You have new mail in /var/spool/mail/root 的原因及解决办法
  • debian系统解决中文乱码
  • pve添加git和pvetools
Recent Comments
  • EdgarTot on proxmox7.3直通显卡
  • Ashvem on proxmox7.3直通显卡
  • Tedvem on proxmox7.3直通显卡
  • Jackvem on proxmox7.3直通显卡
  • Miavem on proxmox7.3直通显卡
Archives
  • March 2023 (1)
  • December 2022 (4)
  • November 2022 (6)
  • April 2022 (1)
  • February 2022 (5)
  • January 2022 (2)
  • December 2021 (3)
  • November 2021 (1)
  • October 2021 (2)
  • September 2021 (1)
  • August 2021 (1)
  • July 2021 (8)
  • June 2021 (14)
  • May 2021 (2)
  • April 2021 (2)
  • March 2021 (10)
  • January 2021 (4)
  • December 2020 (4)
  • November 2020 (13)
  • April 2020 (276)
  • March 2020 (1)
  • June 2019 (5)
  • May 2019 (10)
  • December 2015 (1)