cURL, which stands for client URL, is a command-line tool that makes it easy to transfer data to and from a server with URL syntax.
Today we’re looking at some useful ways to use cURL to download content from a WordPress site. To save an image, download a file, or save a post, you can use the -o curl command, which will save the file in your current directory you’re in via CLI.
Download an image with cURL
Here’s an example of how to save my profile image on this site using curl -o with the file name of image.png by providing it the source URL of the WordPress image attachment:
curl -o image.png https://ash1eygrace.com/wp-content/uploads/2022/03/ash-photo.pngYou can see it download in CLI like so:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 30559 100 30559 0 0 73636 0 --:--:-- --:--:-- --:--:-- 73636
Rate limit a cURL request
You may have noticed the Average Dload speed in the example above, if you’re downloading large files or making a lot of requests, you may want to rate-limit your request as to not overwhelm the server. In this case, you can tack on the --limit-rate and limit it to 1 kilobyte per second command like so:
curl -o myimagename.png --limit-rate 1K https://ash1eygrace.com/wp-content/uploads/2022/03/ash-photo.pngYou can see the average download is a lot lower now, and it spend 15 seconds downloading the image vs the previous download without rate limiting which was downloaded in less than a second.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 30559 100 30559 0 0 1911 0 0:00:15 0:00:15 --:--:-- 3161Download a WordPress post
You can grab the ID of any post on your site and save it to a file on your computer to quickly see it, things like author, categories, and tag ids, etc.
To save a WordPress post using cURL, you’ll use the same -o command to save the file. Give it a desired name in the case below we’ve named it mysavedpost.json.
Finally, provide the URL of the post using your domain, the REST API Endpoint which is /wp-json/wp/v2 with the post ID 964 which looks like this:
curl -o mysavedpost.json https://ash1eygrace.com/wp-json/wp/v2/posts/964The above command will download a raw .json file that includes data about the post like the ID, modified date, its URL, title, the main content, expert, image IDs, and more.
If you open the file in VSC and use an extension that parses JSON to make the raw data pretty it’ll look something like this:


Leave a Reply