Send files to a remote server using scp

/ #Misc

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.


No comments yet...

Add comment

Subscribe to my newsletter