Copying files from a server to your local machine with SCP

← Back

Having a local version of a website for development is a necessity. Chances are, you aren’t saving all the uploaded content for your website in your repository and there are many reasons you may need to download the files to your local machine. Perhaps you’re working on a new machine and you’ve checked out a copy of the project. You have a copy of the database with all the posts and pages but you’re missing all the associated files and this can interfere with development in some cases. Or perhaps you haven’t worked on the site in 6 months and the content has changed on the live site in that time and you’d like your local version to match. Or maybe you’re closing down the server but you’d like to download the content so it can be transferred to a new server. The problem you are left with is that your server has files which you don’t have locally. Provided you have SSH access to your server, the solution is simple: you can create a zip folder and transfer it to your local machine with Secure Copy Protocol (SCP). Here’s how:

Connect to the server via SSH:

ssh <user>@<ip address>

Navigate to the location of the folder you’d like to copy. If you don’t have zip installed on your server, assuming it’s running Ubuntu, you can install it with the following command:

apt-get install zip

You can create a zip folder like so:

zip -r <> <folder>

We now have our zipped folder. All that remains is to copy it to our local machine with SCP. SCP uses SSH for data transfer and relies on the same authentication methods, so provided you can connect to your server via SSH you should be able to use SCP. You can log out of your SSH connection and navigate to the folder on your local machine that you’d like to save the folder in and type the following command:

scp <user>@<ip>:<path to zipped file> .

You should now find the zipped folder ready for use on your local machine.

Recent Blog Posts

How to improve your Google PageSpeed score with Webp images

If you're still serving images in long-time standard formats such as JPEG and PNG then a Google PageSpeed Insights analysis of your site will identify an opportunity to improve your page loading times by serving images in "next-gen" formats. There are several so-called "next-gen" image formats which offer superior compression to JPEG and PNG but in this post we will… Continue reading »

A puzzle with one piece missing

What are WebSockets?

What do WebSockets do? Hypertext Transfer Protocol (HTTP) is unidrectional, meaning requests can only be made by the client. This is a limitation which means that a certain class of web application cannot be built using HTTP alone.¬†WebSockets are a separate communication protocol, fully compatible with HTTP, which allow for bidirectional communication between a client and a server. A protocol… Continue reading »