How do I transfer files from server to local machine?

scp command is being used to copy files from a remote server to a local machine and vice versa. It uses ssh to do secure file transfer.

1. Copy a file from a remote server to a local machine

It will ask the password for remote user

* symbol can be used to copy multiple files by pattern like w3docs* which will copy w3docs.sql, w3docs1.pdf and etc.

2. Copy a directory from a remote server to a local machine

-r should be used for directories

3. Copy a file from a local machine to a remote server

4. Copy a directory from a local machine to a remote server

-r should be used for directories

5. Copy files by using RSA keys

If there is an identity key (RSA) instead of password than -i should be added

Now these days, playing with remote servers is one of the great skill which is necessary for all kind of developers especially full-stack ones and while with them, there is one problem which every person will face which is Sharing data from your local system to remote server. For instance, It can be some already created or downloaded scripts that you may want to execute on remote server. The one option is to push your scripts on Github and then clone them over remote servers which works fine but there is an another tool which we can use much more efficiently and its totally secure. Yes, I am talking about SCP.

Lets go through its formal definition —

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.

⚠️ For more information about SCP. Click here

💡 SCP runs over TCP port 22 by default.

Prerequisites

  • A VPS server.

🔅 I am using temporary AWS’s EC2 Instance as my Remote Host which will be deleted shorty after publishing of this blog post. So, screenshot with ubuntu@ is remote side terminal.

  • We are starting with a file at Local host ( localToRemote.txt ) which we will transfer to Remote host & a file at Remote host ( remoteToLocal.txt ) which we will transfer from there to our Local host.
Left Side is the Local terminal and Right Side is Remote terminal.
  • Make sure you must have added your SSH key on Remote host. Click here to know more about SSH based authentication.

⚜️ 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

and for paths which are on remote host we will add server address first. i.e <user>@<ip_or_domain_name>:<remote_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

❗️ Here scp -i "key.pem"is because my remote server is on EC2. So, instead of simple SSH key based auth, EC2 uses PEM file for login. To know more about all this — Visit this link. If you already have SSH key set-up, you can skip both these terms.

🔅 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 !!

🎧 Listening to “Beerus Sama tea time — 1 hour” and I am also going to have a cup of tea with snacks.

If you like this article, please give it some claps 👏 and share it! If you do not like this post or have any type of questions regarding anything that i mentioned in this post. Feel free to ask me. Just post an issue in my “Ask Me Anything” by clicking here.

For more like this, follow me on Medium or Twitter. To ask a Question visit this link. More about me on my website.

How do I transfer files from server to local?

scp command is being used to copy files from a remote server to a local machine and vice versa. It uses ssh to do secure file transfer.

How do I transfer files from a Windows server to a local machine?

Table Of Content.
Step 1: Connect to your server..
Step 2: Remote Desktop Connection sung your local machine..
Step 3: Open Local Resources option..
Step 4: Selecting drives and folders..
Step 5: Explore connected drive..

How do I transfer files from Linux server to local machine?

To download files from the Linux server to your computer, you need to provide SCP with the local path of the file or directory and the path on the Linux Server where you'd want your file to be uploaded. After running this command, it will require the authentication password of the linux server.

How do I take files from a server?

But you can use another way to transfer files using FTP. In Windows 10, you can use File Explorer to add network location to your local computer and then manually move files from or to it. In Windows Server, you can use Remote Desktop feature to achieve the same goal.