apply cURL in practice


cURL – Client for URLs Program Library and Command Line Program

cURL is a command line tool that allows you to transfer files from shell or bash scrips via protocols such as http, https, ftp, gopher, sftp, ftps or scp. cURL 1997 developed by Daniel Stenberg is very popular with website developers and is licensed under the open source MIT license.

Unique operating systems include cURL in the standard. Many Embedded Linux systems include cURL, as with Synology, cURL is also ported for Windows and is available in the 64 bit and 32 bit versions. PHP supports the cURL functions with the libcrul library.

cURL offers a wide range of applications, so websites can be remotely controlled and tested, forms can be filled out automatically, information from websites can be checked and processed into other processes. In the Linux Shell Console, the installation of wget is not mandatory, but cURL contains extensive parameters and options, and is already pre-installed.

The following are some examples of how to use cURL in the shell console, so Web pages can be retrieved as follows.

This reads the file page.html and outputs it on the standard output. If you want to save the file under the name mypage.html, the following command is used:

Connections to IPv6 hosts are initialized as follows.

The IPv6 address must be enclosed in square brackets.

View your own Internet IP address with cURL.

When a URL has changed, the web page is often redirected to the new URL address, often also http to https redirects. Since cURL does not follow forwards in the standard configuration, you have to pass the parameter -L in this case.

For web pages with self-issued certificate, or outdated TLS v1.0 encryption algorithm, the -k parameter must be applied to allow insecure connections.

When a web site requests user authentication over HTTP, cURL can pass username and password, separated by a colon.

Read the HTTP header with cURL.

The –head parameter instructs cURL to give the output of the HTTP header to the default output. If you want to write the header to the header.txt file, you could do so by pipe operators in the shell, or without the support of the shell by the –dump-header parameter.

The current version 7.63 supports the following 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. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP.

cURL’s FTP client can also interact with FTP servers.

cURL is instructed to output the index of the main directory. Username and password are passed directly with the URL. If you want to list the files subdirectory on the FTP server, it is sufficient to enter the directory to the URL:

With cURL an upload is also possible, for this you pass the parameter -T followed by the file name and if necessary.dem path.

Through this command, cURL copies the mypage file.html to the FTP server to the docs directory under the file names yourpage.html.

Preferably, you should use SFTP, where the file.txt is retrieved over an encrypted connection.

The file transfer also goes via SCP, here the file.txt transferred from the directory docs.

For automated processes via scripts, the user login is not suitable, here you can authenticate with a private key.

The file .txt is transferred from the server’s home directory.

cURL can also be used with Server Message Block (SMB), such as MS LAN Manager and Samba.

Access to file.txt via sharing on a Samba server.

cURL can do even more, the following command line downloads a shell script file and runs it immediately, starting with a period (.).

This command is executable in a Linux bash shell, system configurations and logs are read out and compiled in one file, and stored as a file under /tmp/sysinfo-*.html.

The following is a code example for PHP, the result of the search on Google is output with echo $result:

A look at the man page man curl can be worthwhile, here are all commands with examples of the application of cURL.

cURL Online Manual
Sources Link:

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *