The ab­bre­vi­ation cURL stands for “Client for URLs” or “Curl URL Request Library”. It is a command-line program with the cor­res­pond­ing library for data transfers between computers in a network. The cURL software was developed by the pro­gram­mer Daniel Stenberg. His original goal was to provide users of a chat program with data on currency-exchange rates which was retrieved from various websites. Thanks to its MIT free-software license, cURL can be used freely and has found its way into many operating systems – including Windows 10 which has been using cURL since the 1803 update published in April 2018. Everything curl is a highly com­pre­hens­ive guide and provides in­form­a­tion about what this tool can do for de­velopers. In the following sections, you will find some practical examples of what cURL for Windows can do. You can try some of them out for yourself right now.

What exactly is cURL for Windows?

As with other operating systems, cURL for Windows consists of the ex­ecut­able file curl.exe and the library libcurl, which is an API written in the pro­gram­ming language C that im­ple­ments cURL’s many functions. The commands are executed in the Windows command prompt window (i.e. the command line). There is a defined command syntax for this purpose:

C:\Users\user>curl [options …] <url>

In this example, <url> is the address of the website you want to interact with. The [options …] are used to define the in­struc­tions for per­form­ing op­er­a­tions such as page requests, downloads, uploads, posts, handling forms, and more. Many of the options have two ways to write them:

  • one with a minus sign and letters
  • the other with two minus signs and a command word

For example, to use the GET method as an option, you can do so with either “-G” or “--get”.

Checking the avail­ab­il­ity and version of cURL

First check whether your Windows version has cURL and then which version. To do so, open the command prompt window by typing “cmd” in the Windows search function. Enter the following:

C:\Users\user>curl --version

This will retrieve in­form­a­tion about the available cURL version in your Windows 10 operating system.

As cURL has been further developed, the number of usable protocols has steadily increased. You can see this in the following com­par­is­on in the table below of the two retrieved versions shown in the image above:

7.55.1 (August 2017) 7.70.0 (April 2020)
dict dict
file file
ftp ftp
ftps ftps
gopher
http http
https https
imap imap
imaps imaps
ldap
ldaps
mqtt
pop3 pop3
pop3s pop3s
rtsp
scp
sftp
smb
smbs
smtp smtp
smtps smtps
telnet telnet
tftp tftp

The options for data transfer in a variety of networks were thus also expanded.

In­stalling the current version of cURL

The cURL version installed with Windows is stored in the system as a path that can be reached by both the current user and the ad­min­is­trat­or. If you want to be able to use all of cURL’s available protocols, you will need to have the current version of cURL for Windows installed. The easiest way to do this is to download the current available version as a ZIP file from the developer’s website. There you will also find in­form­a­tion about any changes made (i.e. a changelog). Unzip the file in the File Explorer into a directory (e.g. with the name “curl”). You can also place this directory on your system’s hard drive (e.g. C:\curl\). Copy all the files and dir­ect­or­ies from your unzipped down­loaded cURL file to this new directory. The ex­ecut­able file curl.exe is located in the sub­dir­ect­ory \bin, which also contains the cer­ti­fic­ate file curl-ca-bundle.crt. This file is required to use the SFTP and HTTPS protocol, for instance.

Then, open the Windows command prompt window and enter the following:

# Jump up two directory levels 
C:\Users\user>cd..
C:\Users>cd..
# Jump to the specified directory
C:\cd curl\bin
C:\curl\bin>

Here, you can use all the available functions in cURL for Windows, which are used here in further demon­stra­tions. To test this, all you have to do is access the version as described above. The method described here for updating cURL works for Windows 7, 8, and 10. You can also integrate the current version of cURL into your system. To do so, you need to create a system path and find (!) and de­ac­tiv­ate the old version.

cURL in practice – with simple examples

To use cURL for Windows, enter text commands in the command prompt window. For a quick overview, enter the following command:

C:\curl\bin>curl --help

You can access detailed in­form­a­tion in the manual with the following command:

C:\curl\bin>curl --manual

You should save both outputs that appear in the command prompt window by copying and pasting them as a TXT file in a separate folder. This will allow you to easily access the commands by using the search function in the document and keep the command prompt window free.

Tip

Use a text editor in Windows. You can use it to note the commands for cURL, check them, and then copy them into the command prompt window. This will save you from having to re­peatedly (and frus­trat­ingly) retype commands when typos creep in. You can also use it to save your own sets of commands for future actions, such as with your login in­form­a­tion.

This can be done even faster with the following:

C:\curl\bin >curl --help | clip

The CMD command “clip” preceded by a vertical bar im­me­di­ately copies the current output in the command prompt window to the Windows Clipboard so that you only have to press [Ctrl] + [V] to paste the contents into an empty editor document and then save it.

Saving in­form­a­tion about a website locally

If you need to save in­form­a­tion about a website in a local file, this can be done with a simple cURL routine. The file con­tain­ing the in­form­a­tion should be named infos.html and saved on the local computer in the same directory as the cURL in­stall­a­tion. In Windows, cURL uses the option “-o” (lowercase o, not zero) for this purpose.

curl -o infos.html https://www.n-tv.de/

This request generates a file larger than 700 kilobytes con­tain­ing the specific status of the N-TV news channel’s website at the time of the request.

When you request this file from local data storage in a browser, the website will be displayed in its saved state.

It works the same way with a single file from a web server. The file ref.pdf shall be renamed ref­er­ences.pdf after being down­loaded:

curl -o references.pdf https://mywebsite.tld/ref.pdf
or
curl --output references.pdf https://mywebsite.tld/ref.pdf

Dis­play­ing a website header

To display the content of a website header, which is enclosed in the HTML tags <head>…</head>, you use an option before the requested website address (I = uppercase i):

curl --head https://google.com
# or
curl -I https://google.com

Dis­play­ing more detailed in­form­a­tion

To display even more in­form­a­tion in the output via cURL, you can add the option “-v” or “--verbose”. This option provides in­form­a­tion about the IPv6 address used, the port, any cer­ti­fic­ates and much more.

curl -I https://google.com -v
# or
curl --head https://google.com --verbose

Uploading data via the SFTP protocol

In this situation, the cURL command is a bit more complex since user iden­ti­fic­a­tions for login and veri­fic­a­tion have to be trans­ferred to the server when using SFTP. So, let us get to it:

curl -k sftp://the-example-ftp-server:22 --user user:password -T examplefile.pdf

You can track the progress of the upload in the Windows command prompt window. The uploaded file should now be located in the root directory of your FTP server. If you mistyped the command, cURL for Windows will respond with this short message: “curl: (67) Au­then­tic­a­tion failure”. If you try to perform this transfer with the older cURL version 7.55.1, it will display this message: “curl: (1) Protocol "sftp" not supported or disabled in libcurl”.

Down­load­ing via the SFTP protocol and cURL

With the current version of cURL, downloads are just as easy to perform without a special FTP client, provided that the file to be down­loaded is on the FTP server:

curl -k sftp://the-example-ftp-server:22 --user user:password -o examplefile.pdf
Note

cURL has grown into a powerful tool. Be careful when cURLing on your own server en­vir­on­ment. Using a backup and Windows restore media, you can be on the safe side in case something does go wrong.

cURLing the weather forecast

Re­quest­ing the local weather forecast in this way demon­strates that it is possible to present in­form­a­tion in a more appealing (and useful) way with ASCII char­ac­ters:

curl http://wttr.in/LOCATION

This can be done for any location.

cURL and PHP – a good pairing

To be able to work with cURL in practical everyday pro­gram­ming, cURL is also available in PHP. Check your web server with the following PHP request:

<?php
phpinfo();
?>

Save this code as a file named phpinfo.php, and move it to the root directory of your web server. When you request this file in your browser with ´https://mywebsite.tld/phpinfo.php´, you will be presented with all the in­form­a­tion about the options available in your PHP version, including the avail­ab­il­ity of cURL.

To request a website with ad­di­tion­al in­form­a­tion, all you need are a few lines of PHP code. Here is an example re­quest­ing the German Microsoft website:

<?php
$site = curl_init(); //initialize the cURL handler
curl_setopt($site, CURLOPT_URL, "https://www.microsoft.com/de-de/"); //place the URL
curl_setopt($site,CURLOPT_RETURNTRANSFER,true); // set the optional parameters
curl_setopt($site,CURLOPT_HEADER, true); // display header; omit with „false“
$result=curl_exec($site); // execute the actual cURL
curl_close($site);
echo $result;
?>

Save this code as a file (e.g. under the name curlinfo.php) in the root directory of your web server.

Since the file only contains pure PHP code, the header in­form­a­tion is displayed in the browser’s own font (i.e. un­format­ted). This kind of routine is the first step in embedding data from other websites into your own with PHP and cURL.

Power­Shell vs. the command prompt

Another powerful de­vel­op­ment tool has been im­ple­men­ted in Windows 10: it is called the Power­Shell. It can be iden­ti­fied by the letters "PS" in front of the Windows path after opening it via the Windows icon with a right-click. The Windows Power­Shell is intended to replace the command prompt (known as the “Console”) and provides even more com­pre­hens­ive options for managing websites and servers. However, only some cURL commands can be used in the Power­Shell. The rest must be “trans­lated”.

The “trans­lat­or” is built in and is enabled in the Power­Shell with “Get-Alias” plus the cURL command.

PS C:\WINDOWS\system32> Get-Alias curl
# generates the output
CommandType	Name	Version	Source
-----------	----	-------	------
Alias	curl -> Invoke-WebRequest

This will tell you which Power­Shell command can be used to cURL a website:

PS C:\WINDOWS\system32> Invoke-WebRequest https://google.com/
Go to Main Menu