curl tutorial
Simple Usage
Get the main page from a web-server:
curl https://www.example.com/
Copy And Save
Share
Ask Copilot
Get a README file from an FTP server:
curl ftp://ftp.example.com/README
Copy And Save
Share
Ask Copilot
Get a webpage from a server using port 8000:
curl http://www.example.com:8000/
Copy And Save
Share
Ask Copilot
Get a directory listing of an FTP site:
curl ftp://ftp.example.com/
Copy And Save
Share
Ask Copilot
Get the all terms matching curl from a dictionary:
curl dict://dict.example.com/m:curl
Copy And Save
Share
Ask Copilot
Get the definition of curl from a dictionary:
curl dict://dict.example.com/d:curl
Copy And Save
Share
Ask Copilot
Fetch two documents at once:
curl ftp://ftp.example.com/ https://www.example.com:8000/
Copy And Save
Share
Ask Copilot
Get a file off an FTPS server:
curl ftps://files.are.example.com/secrets.txt
Copy And Save
Share
Ask Copilot
or use the more appropriate FTPS way to get the same file:
curl --ssl-reqd ftp://files.are.example.com/secrets.txt
Copy And Save
Share
Ask Copilot
Get a file from an SSH server using SFTP:
curl -u username sftp://example.com/etc/issue
Copy And Save
Share
Ask Copilot
Get a file from an SSH server using SCP using a private key (not password-protected) to authenticate:
curl -u username: --key ~/.ssh/id_rsa scp://example.com/~/file.txt
Copy And Save
Share
Ask Copilot
Get a file from an SSH server using SCP using a private key (password-protected) to authenticate:
curl -u username: --key ~/.ssh/id_rsa --pass private_key_password
scp://example.com/~/file.txt
Copy And Save
Share
Ask Copilot
Get the main page from an IPv6 web server:
curl "http://[2001:1890:1112:1::20]/"
Copy And Save
Share
Ask Copilot
Get a file from an SMB server:
curl -u "domain\username:passwd" smb://server.example.com/share/file.txt
Copy And Save
Share
Ask Copilot
Download to a File
Get a webpage and store in a local file with a specific name:
curl -o thatpage.html https://www.example.com/
Copy And Save
Share
Ask Copilot
Get a webpage and store in a local file, make the local file get the name of the remote document (if no filename part is specified in the URL, this fails):
curl -O https://www.example.com/index.html
Copy And Save
Share
Ask Copilot
Fetch two files and store them with their remote names:
curl -O www.haxx.se/index.html -O curl.se/download.html
Copy And Save
Share
Ask Copilot
Using Passwords
FTP
To ftp files using name and password, include them in the URL like:
curl ftp://name:
[email protected]:port/full/path/to/file
Copy And Save
Share
Ask Copilot
or specify them with the -u flag like
curl -u name:passwd ftp://ftp.server.example:port/full/path/to/file
Copy And Save
Share
Ask Copilot
FTPS
It is like FTP, but you may also want to specify and use SSL-specific options for certificates etc.
Note that using FTPS:// as prefix is the implicit way as described in the standards while the recommended explicit way is done by using FTP:// and the --ssl-reqd option.
SFTP / SCP
This is similar to FTP, but you can use the --key option to specify a private key to use instead of a password. Note that the private key may itself be protected by a password that is unrelated to the login password of the remote system; this password is specified using the --pass option. Typically, curl automatically extracts the public key from the private key file, but in cases where curl does not have the proper library support, a matching public key file must be specified using the --pubkey option.
HTTP
curl also supports user and password in HTTP(S) URLs. You can download a file like:
curl https://name:
[email protected]/full/path/to/file
Copy And Save
Share
Ask Copilot
or specify user and password separately like in
curl -u name:passwd https://http.server.example/full/path/to/file
Copy And Save
Share
Ask Copilot
HTTP offers many different methods of authentication and curl supports several: Basic, Digest, NTLM and Negotiate (SPNEGO). Without telling which method to use, curl defaults to Basic. You can also ask curl to pick the most secure ones out of the ones that the server accepts for the given URL, by using --anyauth.
Note! According to the URL specification, HTTP URLs can not contain a user and password, so that style does not work when using curl via a proxy, even though curl allows it at other times. When using a proxy, you must use the -u style for user and password.
HTTPS
Probably most commonly used with private certificates, as explained below.
Proxy
curl supports both HTTP and SOCKS proxy servers, with optional authentication. It does not have special support for FTP proxy servers since there are no standards for those, but it can still be made to work with many of them. You can also use both HTTP and SOCKS proxies to transfer files to and from FTP servers.
Get an ftp file using an HTTP proxy named my-proxy that uses port 888:
curl -x my-proxy:888 ftp://ftp.example.com/README
Copy And Save
Share
Ask