Curl Overview
curl
Command Guide
The curl
command is a powerful command line tool that allows you to transfer data to or from a server. It supports a wide range of protocols, including HTTP, HTTPS, FTP, FTPS, and more. In this guide, we will explore some of the most common use cases for the curl
command.
Why Use curl
?
curl
is a versatile tool which allows you to interact with web servers from the command line. Some common use cases for curl
include:
- Downloading files from a server
- Uploading files to a server
- Testing API endpoints
- Debugging network issues
- Automating tasks
Installation
Linux
sudo apt-get install curl
Simple Usage
HTTP GET Request
To make a simple HTTP GET request, you can use the following command:
curl https://example.com/
This will fetch the contents of the specified URL and print them to the terminal.
FTP Download
To download a file from an FTP server, you can use the following command:
curl ftp://ftp.example.com/file.txt
This will download the specified file from the FTP server.
HTTP GET Request on a Specific Port
To make an HTTP GET request on a specific port, you can use the following command:
curl https://example.com:8080/
This will make an HTTP GET request to the specified URL on port 8080.
FTP Directory Listing
To list the contents of an FTP directory, you can use the following command:
curl ftp://ftp.example.com/
This will list the files and directories in the specified FTP directory.
Fetch Two FTP Files
To fetch two files from an FTP server, you can use the following command:
curl ftp://ftp.example.com/file1.txt ftp://ftp.example.com/file2.txt
This will fetch the specified files from the FTP server.
Get a File from an SSH Server using SFTP
To get a file from an SSH server using SFTP, you can use the following command:
curl -u username sftp://example.com/file.txt
This will prompt you for the password of the specified username and download the file from the SSH server.