If you want to test a Remote Server port connection then you need to use below curl command. In this example we are using telnet to test remote server google.com port 443 using curl -v telnet://google.com:443 as shown below. root@localhost # curl -v telnet://google.com:443. About to connect to google.com port 443 (#0). Trying 172.217.161. I don't yet have the reputation necessary to comment on the post that claims curl isn't for ssh or telnet. That is not accurate. Curl handles a multitude of protocols, including telnet, ssh, scp, sftp, ftps, and more. This is the correct syntax for curl: curl -v telnet://127.0.0.1:22. Curl is a command line tool to transfer data from or to a server. Curl is available at the Linux command line, in the Macintosh Terminal and in the Windows Subsystem for Linux. Later versions of Windows 10 include curl in the command prompt. Curl can also be installed from https://curl.haxx.se. This is similar to using telnet to connect to an http service and manually sending an http, i.e GET, OPTIONS or TRACE request. OPTIONS / HTTP/1.1 Host: example.com. Press Enter Twice: 2. Test with CURL – CURL is the another useful utility through which you can test all methods for both http and https websites. How to HTTP with curl. HTTP with libcurl.
command line tool andlibrary
for transferring data with URLs
(since 1998)
Supports...
DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP,LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP,SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT,FTP uploading, HTTP form based upload, proxies, HTTP/2, HTTP/3, cookies,user+password authentication (Basic, Plain, Digest, CRAM-MD5, SCRAM-SHA, NTLM,Negotiate and Kerberos), file transfer resume, proxy tunneling and more.
What's curl used for?
curl is used in command lines or scripts to transfer data. curl is also usedin cars, television sets, routers, printers, audio equipment, mobile phones,tablets, settop boxes, media players and is the Internet transfer engine forthousands of software applications in over ten billion installations.
curl is used daily by virtually every Internet-using human on the globe.
Who makes curl?
curl is free and open source software and existsthanks to thousands of contributors and ourawesome sponsors. The curlproject follows wellestablished open source best practices. You toocan help us improve!
What's the latest curl?
The most recent stable version is 7.76.1, released on 14th of April 2021.Currently, 70 of the listed downloads are of the latest version.
Where's the code?
Check out the latest source code from github.
Everything curl is a detailed and totally free book available in several formats, that explains basically everything there is to know about curl, libcurl and the associated project.
Learn how to use curl. How to use libcurl. How to build them from source or perhaps how the curl project accepts contributions. There's something for everyone in this, from the casual first-time users to the experienced libcurl hackers.
Curl Telnet Example
Everything curl is itself an open project that accepts your contributions and help.
Curl Telnet Close Connection
The free software cURL is one of the oldest and most popular open source projects. The program is written in C and is used to transfer data into computer networks. The name cURL stands for “client URL.” Because it has an open license, programmers can use the program for a wide range of purposes. Currently, cURL is being used in countless devices.
- How does cURL work?
- Practical examples of the cURL command in Linux
- Downloading files with cURL
- Communicating with the server using cURL
- General options
What is cURL?
The cURL software consists of two components. The libcurl software library acts as the backbone for data transfer and 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
- TFTP
The cURL command-line program, on the other hand, acts as a text-based interface and interacts with libcurl via the command line.
This program is an important tool for web development. It allows developers to communicate with servers directly instead of having to go through a browser. Scripts based on cURL commands are used to automate processes, testing, and debugging.
How does cURL work?
The two components in cURL work in different ways.
What is libcurl used for?
The libcurl software library provides functions for transferring data in computer networks. There are language bindings for dozens of popular programming languages. These make it easy for libcurl functions to be used in a wide variety of software programs that communicate with servers.
What is cURL used for?
The cURL command-line program is used for web development. The simplest method is to enter cURL commands into the command line. With the right know-how, it can be used to test and debug servers and APIs.
Instead of typing commands into the command line manually, they can be bundled in scripts. This allows complex operations to be standardized and automated. This includes both uploading and downloading of data and programmatically filling out forms and mirroring entire websites.
The following is the general syntax of a cURL command:
We will use the following form in the examples below:
We have turned the actual URL into a variable. This allows the focus to be placed on the options. The options determine how the cURL request works.
Practical examples of the cURL command in Linux
To use the cURL examples below, you will need the following:
- A computer with Linux or a Unix-like operating system — including macOS
- Access to the command-line window or terminal
- A code editor/plain-text editor for writing commands
You should only use a code editor/plain-text editor to write commands. Under no circumstances should you use a word processing program (e.g. Word, OpenOffice, or LibreOffice) to prepare text for the command line.
An initial test with cURL
First, test whether cURL is installed on your system. To do so, open a command-line window and enter the following command there. You may need to press Enter to execute the code.
If you now see text starting with “curl” and a version number, this means cURL is installed. If cURL is not installed, please follow the instructions in “Everything curl” to install the program.
Use the command “curl --help” and “curl --manual” to learn more about the cURL command.
You should also open a new document in a code editor. You can copy commands to prepare them for use in the command-line window. Once the command is ready, copy it to the command-line window and execute it there.
Commands used in the command-line window are quite powerful. In principle, an incorrectly entered command can cripple the entire system. Therefore, you should not just copy commands you find on the internet and execute them in your home command-line window. Instead, you should have a blank document open in a code editor where you can copy the commands first. This intermediate step allows you to check each command and modify it when necessary before executing it.
Downloading files with cURL
Retrieving data from a server with cURL
In principle, you can use cURL to retrieve any URL. In this context, the term “curl” is used as a verb to describe requesting a URL with cURL. Test the following example:
If you execute the code like written, it will output “data salad.” This is because the returned response to the cURL access will be the Google homepage in HTML. The HTML source code will be directly displayed in the command-line window without any formatting. A browser will be required to display it correctly. It is usually more useful to save the file locally.
Use the “clear” command in the command-line window to clear the screen. This will get rid of undesired data in the command-line window.
Retrieving data with cURL and saving it locally
Let us download a logo from the English version of Wikipedia. The “-O” option (upper case o, not a zero) tells cURL to use the name of the file at the end of the URL. When you use this option, cURL will save the downloaded file locally under the same name.
But what if the URL does not contain a file name? Test the following code:
As you can see, an error is displayed because the URL of the Google homepage does not contain a file name. In this case, you need to use the “-o” option (lower case o) to assign the file a name yourself:
Resuming a download with cURL if it is interrupted
Libcurl Telnet
You may have run into this annoying situation before: you are performing a large download which has already taken hours when it is suddenly interrupted forcing you to start all over again. In this instance, cURL can help with the “-C-” option:
Technically, the option is “-C -” with a space after the C, but the similar version “-C-” is easier to read and remember, so we are using that here.
You can also manually cancel a download that was initiated with cURL if you need to. This is useful for larger files when, for instance, you have to leave the house and take your laptop with you.
You can cancel the current cURL request. To do so, press Ctrl+C. You may need to do this multiple times.
Communicating with the server using cURL
The download functionality of cURL is similar to the popular command-line tool wget. However, cURL is not specifically designed for performing downloads. It is designed for general communication in networks. cURL can thus do much more.
Using cURL to test whether a server is available
You can use cURL to test whether a server is available. In this regard, the way cURL works is similar to the ping command. However, cURL is more versatile due to the number of protocols and options available. In addition, ping works on an internet layer while cURL runs on the application layer. This means that ping tests whether the machine is on the network. In contrast, the following cURL command checks whether and how a server responds:
If the status information is displayed after executing the code, this means that the server is available.
Outputting a header using cURL
In each HTTP request, metadata is exchanged in addition to the actual document. This data is called the HTTP Header and describes both the document and the status of the HTTP request. You have probably already encountered the 404 Not Found error message at one time or another. The error is a type of metadata – the requested document was not found.
Take a look at the output of the header for the URL “google.com.” To do so, use cURL with the “--head” option:
You should see “301 Moved Permanently,” among other information. This is the HTTP status code for a permanent redirect. What you are seeing is a redirect from [google.com] (without the “www”) to [www.google.com].
Instead of using the “--head” option, you can use the equivalent version “-I” (upper case i). It is easy to remember using a mnemonic: you use it to retrieve information for a URL instead of its actual content.
Analyzing redirect chains using cURL
HTTP redirects can be linked together in a sequence. We call this a “redirect chain.” For example, take a website with a homepage that displays the address [https://www.example.com/]. If you try to access the website using the address [http://example.com], this may result in the following redirects:
- [http://example.com] → [https://example.com]
- [https://example.com] → [https://www.example.com]
- [https://www.example.com] → [https://www.example.com/]
Chaining redirects results in unnecessarily long load times and should be avoided. Unfortunately, this is not an easy problem to deal with. When the website is loaded into the browser, the redirects occur without a user seeing much of it. In this instance, cURL can help with the “--location” option: this tells cURL to follow the redirects to the last one. Here we are using the “--head” option because we are not interested in the content of the websites.
Instead of using the “--location” option, you can use the equivalent version “-L” (upper case l).
Transferring data to a server with cURL
In addition to retrieving data, you can also use cURL to transfer data to a server. This may be practical if you want to automate the process of filling out an online form, for example. cURL supports the POST request method as well as GET.
Since transferring data is more complex than retrieving it, we can only provide a rough example here. For more detailed information, read about the HTTP POST method in Everything curl.
Accessing cookies with cURL
HTTP cookies are small pieces of data that are stored locally on your device when you visit most websites. You can view the cookies from websites you visited in your browser and delete them from there. However, this way is usually too tedious for testing purposes. You can also use the cURL option “--cookie-jar” to access the cookies more directly.
You can also tell cURL to transfer cookies using the “--cookie” option.
General options
Some of the cURL options available can be combined with the ones we have already gone over.
Displaying additional information
Sometimes, the information displayed when you execute a cURL command is not quite sufficient. In such a case, you can use the “--verbose” option. When you execute a cURL command with this option, it will provide more information.
Entering a username and password with cURL
Some URLs are protected against unauthorized access with HTTP authentication. But what if you want to access this kind of URL with cURL? If you do not provide a username and password, you will receive the HTTP 401 error message. In this situation, use the following syntax:
You can also use cURL to retrieve data from an FTP server. To do so, you will once again use the --user option to enter the username and password.
Using a proxy with cURL
A proxy is an intermediary server. Proxies can be useful for a number of reasons. For example, some security and performance requirements can be more easily met by using a proxy.
You need to tell cURL if you are connecting to the internet using a proxy. To do so, use the “--proxy” option:
If you need to enter a username and password for the proxy server, you can do so by using the “--proxy-user” option as well. If you do, enter the username and password in the following format: “user:password”.