Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

linux

How to copy from a remote server to a local machine in Linux

Abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In Linux, we use the scp command to securely copy files and folder between two servers.

The basic syntax of scp command is as follows:

scp [OPTIONS] [SRC_ADDRS]:[file|directory] [DST_ADDRS]:[file|directory]

where

  • OPTIONS: These are different flags/options enabled/disabled during the copy operation.
  • SRC_ADDRS dan DST_ADDRS: This is username@ip_address.
  • [file|directory]: The file or directory path.

How to copy a file

We’ll use the following command to copy a file from a remote host to local host.

According to the syntax explained above, let’s assume the following:

  • username is remoteuser
  • ip_address is 10.12.13.1
  • The source file path is /home/Documents/test_doc.txt
  • The destination file path is /User/educative/Downloads/test_doc_copy.txt
scp remoteuser@10.12.13.1:/home/Documents/test_doc.txt /User/educative/Downloads/test_doc_copy.txt

How to copy a directory

We’ll use the following command to copy the contents of the directory in a recursive way from a remote host to local host.

According to the above syntax, let’s assume the following:

  • username is remoteuser
  • ip_address is 10.12.13.1
  • The source directory path is /home/Documents/test_dir
  • The destination file path is /User/educative/Downloads
scp -r remoteuser@10.12.13.1:/home/Documents/test_dir /User/educative/Downloads

RELATED TAGS

linux

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring