CURL is a command-line tool and library for transferring data with URLs. It is free, and many applications use it. In this post, we will share how you can install CURL on Windows. It is somewhat surprising that it is used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, set-top boxes, media players and many more places. Show
Install CURL on Windows 11/10The Windows OS now ships with a copy of CURL. It is already set up, and you can start using it right away. Open the command prompt, and type “curl -help“. If there are no errors, and displays all the options of curl, it’s installed on your Windows 11/10. Along with Curl, Microsoft also rolled out Tar, a command-line tool to extract files and create archives. If for some reason you do not find CURL installed on your Windows OS, here is how to install Curl on Windows. Read: How to zip and unzip files in Windows 11/10 using the built-in feature. 1] Install Git for WindowsDownload Git for Windows, and it will install CURL along with it. You can find it installed under C:\Program Files\Git\mingw64\bin\. Add it to your Windows path, and you will be able to execute it from anywhere. Press the start button, and type Curl (client URL) is a command-line tool powered by the libcurl library to transfer data to and from the server using various protocols, such as HTTP, HTTPS, FTP, FTPS, IMAP, IMAPS, POP3, POP3S, SMTP, and SMTPS. It is highly popular for automation and scripts due to its wide range of features and protocol support. In this article, you will learn how to use curl in Windows with various examples. Let’s get started. Contents Surender Kumar Surender Kumar has more than twelve years of experience in server and network administration. His fields of interest are Windows Servers, Active Directory, PowerShell, web servers, networking, Linux, virtualization, and penetration testing. He loves writing for his blog. Latest posts by Surender Kumar (see all)
Install curl on WindowsAll the modern Windows versions, starting with Windows 10 (version 1803) and Server 2019, have the curl executable pre-installed, so there is no need for a manual installation. To determine the curl location and version in your system, you can use the following commands: where curl curl --version Determine the location and version of curl in Windows The curl --version command also lists the protocols and features supported by the current curl version. If you see an output, as shown in the screenshot above, you’re all set to use the built-in curl utility. If you get an error message instead, curl might not be available, probably because you’re on an earlier version of Windows (e.g., Windows 8.1 or Server 2016). In that case, you might need to manually setup curl in Windows. Curl syntaxThe curl command uses the following syntax: curl [options...] [url] It supports various options, which we will discuss later in this post. As with any other command-line tool, you can use the curl --help command to get help. Getting help with the curl command To get detailed help, you can use curl --help all. The help section is divided into categories, so the curl --help category gets you an overview of all the categories. Now that you’ve become familiar with curl syntax, let’s discuss various use cases with the help of examples. HTTP GET requestWhen you use curl against a URL without specifying any option, the request defaults to the GET method of the HTTP protocol. Try this: curl https://4sysops.com The above command is essentially equivalent to curl --request GET https://4sysops.com, which sends a GET request to 4sysops.com using the HTTPS protocol. To specify the HTTP protocol version (e.g., http/2), use the --http2 option, as shown below: curl --http2 https://4sysops.com For URLs starting with HTTPS, curl first tries to negotiate to establish a http/2 connection and automatically falls back to http/1.1 if the negotiation fails. It also supports other methods, such as HEAD, POST, PUT, and DELETE. To use these methods, along with the curl command, use the --request (or -X) option, followed by the method. Notice that the methods that are available depend on the protocol being used. Get remote file information.As an admin, you might want to be interested in HTTP headers only. This can be done using the --head (or -I) option. Sometimes, a URL might redirect you to another location. In that case, --location (or -L) allows the curl to follow the redirects. You can also use --insecure (or -k) to allow insecure connections to avoid any TLS certificate errors if the target URL is using a self-signed certificate. Use this only when absolutely necessary. All three of these options can be combined in short-notation, as shown in the following command: curl -kIL 4sysops.com View request headers allow insecure connection and follow redirect options with curl You can see that short-notation is particularly useful for combining multiple options. The above command is essentially equivalent to the curl --insecure --head --location 4sysops.com command. The --head (or -I) option also gives you basic information about a remote file without actually downloading it. As shown in the screenshot below, when you use curl with a remote file URL, it displays various headers to give you information about the remote file. curl -IL https://curl.se/windows/dl-7.85.0_5/curl-7.85.0_5-win64-mingw.zip Use curl to view the basic information about remote files The Content-Length header indicates the size of the file (in bytes), Content-Type reveals the media type of the file (for instance image/png, text/htm), Server indicates the type of server application (Apache, Gunicron, etc.), Last-Modified shows the date when file was last changed on the server, and the Accept-Ranges header indicates the support of partial requests from the client for downloads, which essentially means you can resume an interrupted download. Download a fileYou can use curl with the --remote-name option (or -O, in short) to download a file and save it with the same name as on the server. The following command downloads the latest version of curl for Windows from the official website: curl -OL https://curl.se/windows/latest.cgi?p=win64-mingw.zip Downloading a file with a default name and progress indicator using curl The -L option is added to follow redirects, if needed, for locating the resource. If you want to save the file with a new name, use the --output (or -o) option instead. Furthermore, while using the curl command in a script, you might want to suppress the progress indicator using --silent (or -s). Both options can be combined, as shown in the following command: curl -sLo curl.zip https://curl.se/windows/latest.cgi?p=win64-mingw.zip Silently download a file and save with a custom name using curl Resume interrupted downloadThe presence of Accept-Ranges: bytes in the response header literally means that the server supports resumable downloads. To resume an interrupted download, you can use --continue-at (or -C), which accepts an offset (in bytes). Generally, specifying an offset is tricky, so curl offers an easy way of resuming an interrupted download: curl -OLC - https://releases.ubuntu.com/22.04/ubuntu-22.04.1-desktop-amd64.iso Resuming an interrupted download with curl As you can see in the screenshot, I was downloading an Ubuntu iso file, which was interrupted. When I ran the curl command again with the -C option, the transfer was resumed from the byte range where it was interrupted. The minus sign (-) next to -C allows the curl to automatically figure out how and where to resume the interrupted download. Authentication with CurlCurl also supports authentication, allowing you to download a protected file by supplying credentials with the --user (or -u) option, which accepts a username and password in the username:password format. If you skip typing the password, curl will prompt you to type it in no-echo mode. curl -u surender -OL https://techtutsonline.com/secretFiles/sample.zip Downloading a file using username and password authentication with curl If you use a basic authentication method, you have to transfer a username and password, which means that you should use a secure protocol such as HTTPS (instead of HTTP) or FTPS (instead of FTP). If, for some reason, you have to use an unencrypted protocol, make sure you use an authentication method that doesn’t transmit credentials in clear text (for instance, Digest, NTLM, or Negotiate authentication). Curl also supports the use of .curlrc, _curlrc, and .netrc config files, allowing you to define various curl options in a file and then to include the file in your command with curl --config (or curl -K), which is particularly useful for scripting. Upload a fileThe --upload-file (or -T) option allows you to upload a local file to a remote server. The following command shows how to upload a file from a local system to a remote web server using the FTPS protocol: curl [options...] [url]0 Uploading a file to a remote server using curl The -k option is included to avoid certificate errors if the web server uses a self-signed certificate. The trailing slash at the end of the URL tells curl that the destination is a directory. You could specify multiple file names, such as “{sample1.zip,sample2.zip}.” The following command shows how to upload multiple files with a single curl command: curl [options...] [url]1 Upload multiple files to a remote server using curl Quote a commandAs already discussed, curl supports various methods based on the underlying protocol being used. You can send additional commands using --quote (or -Q) to perform a particular operation either before or after the regular curl operation; for instance, if you want to download a file from a remote server using the FTPS protocol and want the file to be removed from the server once it has been downloaded successfully. To do this, you can run the command shown below: curl [options...] [url]2 Delete a file after successful download using curl command Here, I downloaded the sample1.zip file from an FTPS server with the help of the -O option. After the -Q option, I added a minus sign (-) just before the DELE command, which tells the curl to send the DELE sample1.zip command immediately after the file is downloaded successfully. Likewise, if you want to send a command to the server before performing the actual curl operation, use a plus (+) sign instead of a minus sign. Change the user-agentThe user-agent tells a server what type of client is sending the request. When you send a curl request to the server, the curl/<version> user-agent is used by default. If the server is configured to block the curl requests, you can specify a custom user-agent using --user-agent (or -A). The following command sends a common Google Chrome user-agent: curl [options...] [url]3 Use a custom user agent with a curl command to avoid server blocks The above screenshot shows that a normal curl request was forbidden by the web server (with a 403 Forbidden response), but when I passed a custom user-agent, the request was successful, returning a 200 OK response. Send a cookieBy default, the curl request does not send or store cookies. To write a cookie, use the --cookie-jar (or -c) option, and with --cookie (or -b), you can send a cookie: curl [options...] [url]4 The first command writes a cookie file, and the second command sends the cookie with a curl request. You can also send a cookie in 'name = value’' format, as shown below: curl [options...] [url]5 Send multiple cookies using a curl command I used the echo.hoppscotch.io website to view HTTP request headers that aren’t normally visible to clients sending a request. If you don’t want to use this website, you could use the –verbose (or -v) option to see your request in raw form (which will show request headers, too). Use a proxy serverDo you use a proxy server to connect to the internet? No problem! Curl lets you specify a proxy server using the --proxy (or -x) option. If your proxy server requires authentication, add --proxy-user (or -U): curl [options...] [url]6 The proxy server is specified in the server:port format, and the proxy user is specified in the username:password format. Again, you could skip typing the password for the proxy user, and curl will prompt you to enter it in no-echo mode. Use a proxy server and authentication with a curl command Additional request headersSometimes, you might want to send additional information along with your request to the server. With curl, you can do so easily by using --header (or -H), as shown in the following command: curl [options...] [url]7 Specify additional headers with a curl request You could send any information that isn’t available with standard HTTP request headers. In this example, I sent my operating system name. I also added the -v option this time to enable verbose output, which displayed the additional header being sent along with my curl request. Send an emailSince curl supports the SMTP protocol, you could use it to send an email message. The following command shows how to send an email using curl: curl [options...] [url]8 Send an email message using a curl command Let’s quickly discuss the options used:
The following screenshot shows the email message I received in my inbox: Viewing the email message sent with curl Viewing the email message sent with curl Subscribe to 4sysops newsletter!These are just a few examples, but there is a lot more you can do with curl. I highly recommend checking out curl help and experimenting with it. You'll notice what a powerful command curl is. Can I run curl on Windows?Using curl in Windows
You can use the Windows command prompt to run the curl examples. To start the command prompt, open the Start menu, type cmd in the search box, and press Enter. By default, curl isn't installed in Windows 10, version 1803 or earlier. See Installing curl below to install it on your system.
How do I know if curl is installed on Windows 10?Open the command prompt, and type “curl -help“. If there are no errors, and displays all the options of curl, it's installed on your Windows 11/10.
How do I install curl command in Windows?Extracting and setting up curl. Click the Windows 10 start menu. ... . You'll see the search result Edit the system environment variables. ... . A System Properties window will popup. ... . Select the "Path" variable under "System variables" (the lower box). ... . Click the Add button and paste in the folder path where curl.exe lives.. |