What is cURL?

curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.

You can use curl via the command lines or scripts to transfer data.

In fact, it is ubiquitous that it is also used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, settop boxes, media players and is the internet transfer backbone for thousands of software applications affecting billions of humans daily.

Pre-requisite
Check if you have Curl Installed in your System using the command.

curl --version

or

which curl

Since cURL is installed by default on mac OS, you will see an output like this if you are on Mac:

curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.4 zlib/1.2.11 nghttp2/1.24.1
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy

You can also install on Mac using Homebrew:

You can do that by visiting https://docs.brew.sh/Installation or running:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

then:

brew install curl

Installing CURL on a Linux machine:

Ubuntu:

sudo apt-get update
sudo apt-get install curl
sudo systemctl restart apache2

If you need cURL for PHP:

First, check your PHP version:

php --version

then:

sudo apt-get install php-curl
sudo systemctl restart apache2

Verify cURL:

sudo dpkg -l curl

You can also visit cURL’s website and download the latest curl version by copying the link and using wget command

wget https://curl.haxx.se/download/curl-7.63.0.tar.gz

Unpack the tarball file:

tax -xvf curl-7.57.0.tar.gz

Move to the folder:

 cd curl-7.63.0

Install the C compiler:

apt-get install build-essential

Compile the source code:

./configure
make
make install

Centos/RHEL:

sudo yum update
sudo yum install curl
sudo yum install php-curl

Fedora:

 sudo dnf -y install php-curl

Arch Linux:

update:

sudo pacman -Sy

install:

 sudo pacman -S curl

verify:

sudo pacman -Qi curl

Alpine Linux:

add cURL:

apk add curl

verify:


sudo apk search curl

 

Windows:
For Windows, you will need to download and install cURL by creating a new folder called curl in your C: drive.

C:\curl

Then visit https://curl.haxx.se/download.html and download one of the following zip files:

If you have a Windows 64 system, scroll to the Win64 – Generic section and look for the latest Win64 ia64 zip version with SSL support.

It’s normally second in the list. Click the version number to start the download.

If you have a Windows 32 system, scroll to the Win32 – Generic section and look for the latest Win32 zip version with SSL support. It’s normally second in the list.

Click the version number to start the download.

Unzip the downloaded file and move the curl.exe file to your C:\curl folder.

Go to http://curl.haxx.se/docs/caextract.html and download the digital certificate file named cacert.pem.

The PEM file contains a bundle of valid digital certificates.

The certificates are used to verify the authenticity of secure websites.

They’re distributed by certificate authority (CA) companies such as GlobalSign and VeriSign.

The PEM file allows cURL to connect securely to an API using the Secure Sockets Layer (SSL) protocol.

Move the cacert.pem file to your C:\curl folder and rename it curl-ca-bundle.crt.

Add the curl folder path to your Windows PATH environment variable so that the curl command is available from any location at the command prompt.

Update the variable as follows:

In the Start menu, right-click This PC and select More > Properties.

Please note that In Windows 7, you should right-click Computer and select Properties.

Click Advanced System Settings.

In the Advanced tab, click the Environment Variables button on the lower right side.

Select the “Path” variable in System Variables, and click Edit.

In the Edit environment variable dialog box, click New and add the path to the curl.exe file. Example: C:\curl.

Windows 7: In the Variable Value textbox, append a semicolon to the value, followed by the path to the curl.exe file. Example: ;C:\curl

Keep clicking OK to accept the change and close the dialog box.

 

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.

 

Using cURL:

Checking google.com headers:

curl -I https://www.google.com

Or download a file from a server using curl itself:


$ curl -O https://domain_name.com/$file.tar.gz # Save as $file.tar.gz
$ curl -o newfile.tar.gz https://domain_name.com/$file.tar.gz # Save as $newfile.tar.gz

You can resume a broken download with the curl command as follows:


curl -L -O -C - http://ftp.ussg.iu.edu/linux/centos/latest/isos/file.iso

Download multiple files info.html and about.html even from different sources in one go:


$ curl -O https://site1.com/info.html -O https://site2.com/about.html

You can combine curl with xargs (https://en.wikipedia.org/wiki/Xargs) to download files from a list of URLs in a file:


$ xargs -n 1 curl -O < listurls.txt

You can still do all these even when running behind a proxy listening on port 8080 at proxy.domain_name.com:


$ curl -x proxy.yourdomain.com:8080 -U user:password -O https://domain_name.com/$file.tar.gz

Upload a local file named $localfile.tar.gz to sftp://ftpserver using cURL:


$ curl -u username:password -T $localfile.tar.gz sftp://ftpserver
$ curl -u username:password -T $localfile.tar.gz scp://ftpserver

For a more in-depth guide on how to use curl, a free book called Everything curl that is available in several formats is a great place to start.

The HTML version can be found at https://curl.haxx.se/book.html.

You can also see cURL’s documentation at https://ec.haxx.se/.

Or simply the best two things:

$ man curl
$ info curl
War diese Antwort hilfreich? 1 Benutzer fanden dies hilfreich (3 Stimmen)