Send files to a remote server using scp

/ #Bash


Sending files using the command line can be tricky. But by using a command called scp, it might be easier than you think.

From time to time, you need to transfer files to a remote server. If you don't have a (s)ftp client or you just want to know how to do it, then keep reading.

Sending a file

Let's say you're in a folder on your computer where you have a file called "filename.txt". You want to send this to your server and put it in the root folder. Here is how you would solve that:

$ scp filename.ext username@serverip:.

The "." behind the serverip: is the location you send the file to. If you change it to "server:foldername/" it will be put in a folder called "foldername".

Sending a folder

The command above will not allow you to send folders. But it's relatively easy to send folders too with this command.

$ scp -r foldername username@serverip:.

As you can see, the command is almost identical. We added a parameter "-r" which means recursive.

Downloading files

As a little bonus: if you want to get files from a server instead, you do it with scp, but the other way around like this:

$ scp username@serverip:filename.txt .

If you run this command, you will download a file called "filename.txt" from the root of your server and put it in the folder where you run the command.

Comments

Aditya Priyadarshi | Oct 05, 21 07:32

Whoops look like you have forgot to mention how to download the `scp` Mr. Stein,

secure contain protect


Stein Ove Helset | Oct 05, 21 07:50

"scp" comes with all Mac OS X and Linux installations :-)

Add comment

Info

Please log in to comment!

Newsletter

Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.