Ghost Tips & Tricks #11 / Download and Upload Images on DigitalOcean

Hello everyone,

This is issue number #11 of Ghost Tips & Tricks. Brought to you by Aspire Themes. Premium and high-quality Ghost themes.


Using the command line, you can download and upload your Ghost CMS images folder. I assume you can already access your DigitalOcean Ghost droplet from the command line locally from your computer.

I will use the SCP command-line tool. SCP term is shorthand of secure copy. It allows to securely transfer files between a remote server and a local machine. In our case, it will copy the images from the Ghost server to the local computer and vise versa.

Zip Images Folder

The first step for downloading the images is to log in to your DigitalOcean Ghost server and zip the images folder.

Login to your DigitalOcean remote server with your droplet IP address.

Replace 207.154.195.220 with your IP.


ssh root@207.154.195.220

Go to the Ghost installation content path.


cd /var/www/ghost/content/

Zip the images folder using the zip command.


zip -r images.zip images

You may need to install the zip command tool first if it is not available on your server.

The command line will check whether the zip tool is available or not and then give you instructions to install it if it is not available.

Now, you have the images.zip file ready for download.

Working with SCP

The SCP command needs two parameters, the first is the remote location file path, and the second is the local path.


scp REMOTE_PATH LOCAL_PATH

In our case, the remote path will be something like:


root@207.154.195.220:/var/www/ghost/content/images.zip

And the local bath, for example, will be on my desktop.


/Users/ahmadajmi/Desktop

Download Images

Combining the previous parameters, you can use the following command to download the images zipped file.


scp root@207.154.195.220:/var/www/ghost/content/images.zip /Users/ahmadajmi/Desktop

Upload Images

The other scenario is to upload the images from your local machine to the remote server; you can use the same concept. Flip the parameters to make the local path comes first and then the remote path last.

So, I assume the images.zip is on the desktop; the upload command will be.


scp /Users/ahmadajmi/Desktop/images.zip root@159.65.227.236:/var/www/ghost/content/

Unzip Images

After uploading the images.zip to the remote server, you can use the unzip command to unzip it.


unzip -o images.zip


That’s all that I wanted to share today, and I hope you find this post helpful.

Checkout previous parts of the Ghost Tips & Tricks series:

Also, check out my Ghost Websites Inspiration and Ghost Newsletter series.

Stay safe!

Ahmad

2 Likes

This is so helpful, @ahmadajmi. Thank you. You are a blessing to the Ghost community! :raised_hands: :pray:

1 Like

Thanks, Donald!

There’s a problem with this. Specifically, permissions…

For example… let’s say you move servers (as I am) from local to hosted… you’ll want to copy the image folder. Once you do, and put it where it belongs on the new server…the permissions are different. This could be ftp’d up there or scp’d up there - I’ve tried both methods on fresh installations (the same effect on both).

When you go to run a command like ghostupdate you get the following error message:

One or more errors occurred.

1) Checking content folder ownership

Message: Your installation folder contains a directory or file with incorrect permissions:
- ./content/images.zip
Run sudo chown -R ghost:ghost ./content and try again.

If you run the command:

sudo chown -R ghost:ghost ./content

then it works fine.

However, you shouldn’t have to do that step each and every time.

1 Like

Good point; thanks for sharing! This will also fix the 500 error issue when uploading a post featured image.