0% found this document useful (0 votes)
3 views

curl

cURL is a command line tool for transferring data using various protocols, designed for automation without user interaction. It supports multiple flags for customizing requests, such as specifying headers, authentication, and request methods. Additionally, cURL can download, upload files, limit transfer rates, and even send emails via SMTP.

Uploaded by

jatinbajpai1993
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

curl

cURL is a command line tool for transferring data using various protocols, designed for automation without user interaction. It supports multiple flags for customizing requests, such as specifying headers, authentication, and request methods. Additionally, cURL can download, upload files, limit transfer rates, and even send emails via SMTP.

Uploaded by

jatinbajpai1993
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

curl is a command line tool to transfer data to or from a server, using any of the supported

protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP or
FILE). curl is powered by Libcurl. This tool is preferred for automation, since it is designed to
work without user interaction. curl can transfer multiple file at once.

Common cURL flags

You'll see the following cURL flags in the examples in the Zendesk REST API
docs.

-H

Specifies any extra header content to include in the HTTP request. API requests
that submit data to our servers typically include the data's content type.
Example:

Example: -H "Content-Type: application/json".

-u

Specifies the user name and password to use for server authentication. The user
name and password are separated by a colon.

Example: -u [email protected]:mypassword

-v

Makes the response more verbose.

-X

Specifies the request method to use when communicating with the HTTP server.
Example: PUT or POST.

Note: GET is the default method so you don't need to specify it.

Example: -X PUT

-G --data-urlencode

Used for API endpoints that send data in a query string, such as the Search API.
The --data-urlencode option url-encodes the query string. The -G flag specifies
that the url-encoded data is for a GET request rather than a POST request.

For example, suppose you want to run the following search using the List Search
Results endpoint:
.../api/v2/search.json?query=type:ticket status:open

The cURL command looks like this:

curl "https://{subdomain}.zendesk.com/api/v2/search.json" \
-G --data-urlencode "query=type:ticket status:open" \
-v -u {email_address}:{password}

curl https://www.geeksforgeeks.org
This should display the content of the URL on the terminal. The URL syntax is protocol
dependent and multiple URLs can be written as sets like:
curl http://site.{one, two, three}.com
URLs with numeric sequence series can be written as:
curl ftp://ftp.example.com/file[1-20].jpeg
Progress Meter: curl displays a progress meter during use to indicate the transfer rate,
amount of data transferred, time left etc.
curl -# -o ftp://ftp.example.com/file.zip
curl --silent ftp://ftp.example.com/file.zip
If you like a progress bar instead of meter, you can use the -# option as in the example
above, or –silent if you want to disable it completely.
Example:

Options:
 -o : saves the downloaded file on the local machine with the name provided in the
parameters.
Syntax:
curl -o [file_name] [URL...]
Example:
curl -o hello.zip ftp://speedtest.tele2.net/1MB.zip
Output:

The above example downloads the file from FTP server and saves it with the
name hello.zip.
 -O : This option downloads the file and saves it with the same name as in the URL.
Syntax:
curl -O [URL...]
Example:
curl -O ftp://speedtest.tele2.net/1MB.zip
Output:

 -C – : This option resumes download which has been stopped due to some
reason. This is useful when downloading large files and was interrupted.
Syntax:
curl -C - [URL...]
Example:
curl -C - -O ftp://speedtest.tele2.net/1MB.zip

 –limit-rate : This option limits the upper bound of the rate of data transfer and
keeps it around the given value in bytes.
Syntax:
curl --limit-rate [value] [URL]
Example:
curl --limit-rate 1000K -O ftp://speedtest.tele2.net/1MB.zip
Output:

The command limits the download to 1000K bytes.


 -u : curl also provides options to download files from user authenticated FTP
servers.
Syntax:
curl -u {username}:{password} [FTP_URL]
Example:
curl -u demo:password -O ftp://test.rebex.net/readme.txt
Example:

 -T : This option helps to upload a file to the FTP server.


Syntax:
curl -u {username}:{password} -T {filename} {FTP_Location}
If you want to append a already existing FTP file you can use the -a or –
append option.
 –libcurl :This option is very useful from a developers perspective. If this option is
appended to any cURL command, it outputs the C source code that uses libcurl for
the specified option. It is the code similar to the command line implementation.
Syntax:
curl [URL...] --libcurl [filename]
Example:
curl https://www.geeksforgeeks.org > log.html --libcurl code.c
Output:
The above example downloads the HTML and saves it into log.html and the code
in code.c file. The next command shows the first 30 lines of the code.
 -x, –proxy : curl also lets us use a proxy to access the URL.
Syntax:
curl -x [proxy_name]:[port] [URL...]
If the proxy requires authentication, it can be used with the command:
curl -u [user]:[password] -x [proxy_name]:[port] [URL...]
 Sending mail : As curl can transfer data over different protocols, including SMTP,
we can use curl to send mails.
Syntax:
curl –url [SMTP URL] –mail-from [sender_mail] –mail-rcpt [receiver_mail] -n –ssl-
reqd -u {email}:{password} -T [Mail text file]
 DICT protocol : The Libcurl defines the DICT protocol which can be used to easily
get the definition or meaning of any word directly from the command line.
Syntax:
curl [protocol:[dictionary_URL]:[word]
Example:
curl dict://dict.org/d:root
Output:

Note: There are a number of other options provided by cURL which can be checked on
the man page. The Libcurl library has been ported into various programming languages.
It’s advisable to visit the individual project site for documentation.

You might also like