Transferring files between remote server and local system

Gaurav Mehla
Mar 15, 2018 · 4 min read

The SCP ( Secure Copy Protocol ) is a network protocol, based on the BSD RCP protocol, which supports file transfers between hosts on a network.

SCP allows files to be copied to, from, or between different hosts. It uses SSH for data transfer and provides the same authentication and same level of security as SSH.

Prerequisites

  • A VPS server.
Left Side is the Local terminal and Right Side is Remote terminal.

⚜️ The list

  1. From Local host to the Remote host
  2. From Remote host to Local host
  3. Multiple files from Local host to Remote host
  4. Directory from Local host to Remote host
  5. Directory from Remote host to Local host

⚜️ Variables Used

  • user : Username of the Remote host.
  • remote_host : Address of the remote host. Either IP or Domain Name.
  • file_path : Path of file on Local host
  • remote_file_path : Path of file on Remote host
  • remote_dir : Path of directory on Remote host
  • local_dir : Path of directory on Local host

Before starting

Basic structure of SCP command is : —
scp <OPTIONS> <SOURCE_FILE_OR_DIR> <TARGET_FILE_OR_DIR>

⚜️ Let’s Begin

🔅 File from Local host to the Remote host

scp <file_path> <user>@<remote_host>:<remote_dir>

Example of Local host to the Remote host

🔅 File from Remote host to the Local host

scp <user>@<remote_host>:<remote_file_path> <local_dir>

Example of Remote host to the Local host ( both side are local terminals )

You Can share any file using these commands. i.e .zip , .tar, etc.

🔅 Multiple files from Local host to the Remote host

scp <file_path> <file_path> <user>@<remote_host>:<remote_dir>

Example of sharingMultiple files from Local host to the Remote host

🔅 Directory from Local host to the Remote host

scp -r <local_dir> <user>@<remote_host>:<remote_dir>

Example of sharing Directory from Local host to the Remote host

🔅 Directory from Remote host to the Local host

scp -r <user>@<remote_host>:<remote_dir> <local_dir>

Example of Directory from Remote host to the Local host ( both sides are local terminals )

That’s it!!

Happy Coding !!


_devblogs

Stories for Full-Stack Web developers which help them in pursuing their goals as a developer, mastering the modern web technologies and *hacking the web.

Gaurav Mehla

Written by

Software engineer & Web hacker. Spent 30+% of life on playing with JS

_devblogs

_devblogs

Stories for Full-Stack Web developers which help them in pursuing their goals as a developer, mastering the modern web technologies and *hacking the web.