GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing curl.se — curl - Tutorial curl tutorialSimple UsageGet the main page from a web-server:
Get a README file from an FTP server:
Get a webpage from a server using port 8000:
Get a directory listing of an FTP site:
Get all terms matching curl from a dictionary:
Get the definition of curl from a dictionary:
Fetch two documents at once:
Get a file off an FTPS server:
or use the more appropriate FTPS way to get the same file:
Get a file from an SSH server using SFTP:
Get a file from an SSH server using SCP using a private key (not password-protected) to authenticate:
Get a file from an SSH server using SCP using a private key (password-protected) to authenticate:
Get the main page from an IPv6 web server:
Download to a FileGet a webpage and store in a local file with a specific name:
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):
Fetch two files and store them with their remote names:
Using PasswordsFTPTo ftp files using name and password, include them in the URL like:
or specify them with the
FTPSIt is like FTP, but you may also want to specify and use SSL-specific options for certificates etc. Note that using SFTP / SCPThis is similar to FTP, but you can use the HTTPcurl also supports user and password in HTTP(S) URLs. You can download a file like:
or specify user and password separately like in
HTTP offers many different methods of authentication and curl supports several: Basic, Digest 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
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 HTTPSProbably most commonly used with private certificates, as explained below. Proxycurl 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:
Get a file from an HTTPS server that requires user and password, using the same proxy as above:
Some proxies require special authentication. Specify by using -U as above:
A comma-separated list of hosts and domains which do not use the proxy can be specified as:
If the proxy is specified with curl also supports SOCKS4 and SOCKS5 proxies with See also the environment variables curl supports that offer further proxy control. Most FTP proxy servers are set up to appear as a normal FTP server from the client's perspective, with special commands to select the remote FTP server. curl supports the
See the manual for your FTP proxy to determine the form it expects to set up transfers, and curl's PipingGet a key file and install it as a trusted one (when on a system that uses
The '|' pipes the output to stdin. RangesHTTP 1.1 introduced byte-ranges. Using this, a client can request to get only one or more sub-parts of a specified document. curl supports this with the Get the first 100 bytes of a document:
Get the last 500 bytes of a document:
curl also supports simple ranges for FTP files as well. Then you can only specify start and stop position. Get the first 100 bytes of a document using FTP:
UploadingFTP / FTPS / SFTP / SCPUpload all data on stdin to a specified server:
Upload data from a specified file, login with user and password:
Upload a local file to the remote site, and use the local filename at the remote site too:
Upload a local file to get appended to the remote file:
curl also supports ftp upload through a proxy, but only if the proxy is configured to allow that kind of tunneling. If it does, you can run curl in a fashion similar to:
HTTPUpload all data on stdin to a specified HTTPS site:
Note that the HTTP server must have been configured to accept PUT before this can be done successfully. For other ways to do HTTP data upload, see the POST section below. Verbose / DebugIf curl fails where it is not supposed to, if the servers do not let you in, if you cannot understand the responses: use the
To get even more details and information on what curl does, try using the
Detailed InformationDifferent protocols provide different ways of getting detailed information about specific files/documents. To get curl to show detailed information about a single file, you should use For HTTP, you can get the header information (the same as Store the HTTP headers in a separate file (headers.txt in the example):
Note that headers stored in a separate file can be useful at a later time if you want curl to use cookies sent by the server. More about that in the cookies section. POST (HTTP)It is easy to post data using curl. This is done using the Post a simple
Or automatically URL encode the data.
How to post a form with curl, lesson #1: Dig out all the If there is a normal post, you use
The variable names are the names set with Example: (say if We want to enter user To post to this, you would enter a curl command line like:
While
If the content-type is not specified, curl tries to guess from the file extension (it only knows a few), or use the previously specified type (from an earlier file if several files are specified in a list) or else it uses the default type Emulate a fill-in form with
To send two files in one post you can do it in two ways: Send multiple files in a single field with a single field name:
Send two fields with two field names
To send a field value literally without interpreting a leading ReferrerAn HTTP request has the option to include information about which address referred it to the actual page. curl allows you to specify the referrer to be used on the command line. It is especially useful to fool or trick stupid servers or CGI scripts that rely on that information being available or contain certain data.
User AgentAn HTTP request has the option to include information about the browser that generated the request. curl allows it to be specified on the command line. It is especially useful to fool or trick stupid servers or CGI scripts that only accept certain browsers. Example:
Other common strings:
Note that Internet Explorer tries hard to be compatible in every way:
Mozilla is not the only possible User-Agent name:
CookiesCookies are generally used by web servers to keep state information at the client's side. The server sets cookies by sending a response line in the headers that looks like If you have received a page from a server that contains a header like:
it means the server wants that first pair passed on when we get anything in a path beginning with Example, get a page that wants my name passed in a cookie:
curl also has the ability to use previously received cookies in following sessions. If you get cookies from a server and store them in a file in a manner similar to:
... you can then in a second connect to that (or another) site, use the cookies from the
While saving headers to a file is a working way to store cookies, it is however error-prone and not the preferred way to do this. Instead, make curl save the incoming cookies using the well-known Netscape cookie format like this:
Note that by specifying
The file to read cookies from must be formatted using plain HTTP headers OR as Netscape's cookie file. curl determines what kind it is based on the file contents. In the above command, curl parses the header and store the cookies received from www.example.com.
curl sends the stored cookies which match the request to the server as it follows the location. The file To read and write cookies from a Netscape cookie file, you can set both
Progress MeterThe progress meter exists to show a user that something actually is happening. The different fields in the output have the following meaning:
From left-to-right:
The Speed Limitcurl allows the user to set the transfer speed conditions that must be met to let the transfer keep going. By using the switch To have curl abort the download if the speed is slower than 3000 bytes per second for 1 minute, run:
This can be used in combination with the overall time limit, so that the above operation must be completed in whole within 30 minutes:
Forcing curl not to transfer data faster than a given rate is also possible, which might be useful if you are using a limited bandwidth connection and you do not want your transfer to use all of it (sometimes referred to as bandwidth throttle). Make curl transfer data no faster than 10 kilobytes per second:
or
Or prevent curl from uploading data faster than 1 megabyte per second:
When using the Config Filecurl automatically tries to read the The config file could be made up with normal command line switches, but you can also specify the long options without the dashes to make it more readable. You can separate the options and the parameter with spaces, or with If you want the parameter to contain spaces, you must enclose the entire parameter within double quotes ( NOTE: You must specify options and their arguments on the same line. Example, set default time out and proxy in a config file:
Whitespaces ARE significant at the end of lines, but all whitespace leading up to the first characters of each line are ignored. Prevent curl from reading the default file by using -q as the first command line parameter, like:
Force curl to get and display a local help page in case it is invoked without URL by making a config file similar to:
You can specify another config file to be read by using the
Extra HeadersWhen using curl in your own programs, you may end up needing to pass on your own custom headers when getting a webpage. You can do this by using the Example, send the header
This can also be useful in case you want curl to send a different text in a header than it normally does. The
FTP and Path NamesDo note that when getting files with a
If you want the README file from the root directory of that same site, you need to specify the absolute filename:
(I.e with an extra slash in front of the filename.) SFTP and SCP and Path NamesWith sftp: and scp: URLs, the path name given is the absolute name on the server. To access a file relative to the remote user's home directory, prefix the file with
FTP and FirewallsThe FTP protocol requires one of the involved parties to open a second connection as soon as data is about to get transferred. There are two ways to do this. The default way for curl is to issue the PASV command which causes the server to open another port and await another connection performed by the client. This is good if the client is behind a firewall that does not allow incoming connections.
If the server, for example, is behind a firewall that does not allow connections on ports other than 21 (or if it does not support the The
Download with
Download with
Network InterfaceGet a webpage from a server using a specified port for the interface:
or
HTTPSSecure HTTP requires a TLS library to be installed and used when curl is built. If that is done, curl is capable of retrieving and posting documents using the HTTPS protocol. Example:
curl is also capable of using client certificates to get/post files from sites that require valid certificates. The only drawback is that the certificate needs to be in PEM-format. PEM is a standard and open format to store certificates with, but it is not used by the most commonly used browsers. If you want curl to use the certificates you use with your favorite browser, you may need to download/compile a converter that can convert your browser's formatted certificates to PEM formatted ones. Example on how to automatically retrieve a document using a certificate with a personal password:
If you neglect to specify the password on the command line, you are prompted for the correct password before any data can be received. Many older HTTPS servers have problems with specific SSL or TLS versions, which newer versions of OpenSSL etc use, therefore it is sometimes useful to specify what TLS version curl should use.:
Otherwise, curl attempts to use a sensible TLS default version. Resuming File TransfersTo continue a file transfer where it was previously aborted, curl supports resume on HTTP(S) downloads as well as FTP uploads and downloads. Continue downloading a document:
Continue uploading a document:
Continue downloading a document from a web server
Time ConditionsHTTP allows a client to specify a time condition for the document it requests. It is For example, you can easily make a download that only gets performed if the remote file is newer than a local copy. It would be made like:
Or you can download a file only if the local file is newer than the remote one. Do this by prepending the date string with a
You can specify a plain text date as condition. Tell curl to only download the file if it was updated since January 12, 2012:
curl accepts a wide range of date formats. You always make the date check the other way around by prepending it with a dash ( DICTFor fun try
Aliases for
Commands that break the URL description of the RFC (but not the DICT protocol) are
Authentication support is still missing LDAPIf you have installed the OpenLDAP library, curl can take advantage of it and offer Default protocol version used by curl is LDAP version 3. Version 2 is used as a fallback mechanism in case version 3 fails to connect. LDAP is a complex thing and writing an LDAP query is not an easy task. Familiarize yourself with the exact syntax description elsewhere. One such place might be: RFC 2255, The LDAP URL Format To show you an example, this is how to get all people from an LDAP server that has a certain subdomain in their email address:
You also can use authentication when accessing LDAP catalog:
By default, if user and password are provided, OpenLDAP/WinLDAP uses basic authentication. On Windows you can control this behavior by providing one of
On Windows, if no user/password specified, auto-negotiation mechanism is used with current logon credentials (SSPI/SPNEGO). Environment Variablescurl reads and understands the following proxy related environment variables:
They should be set for protocol-specific proxies. General proxy should be set with
A comma-separated list of hostnames that should not go through any proxy is set in (only an asterisk,
If the hostname matches one of these strings, or the host is within the domain of one of these strings, transactions with that node is not done over the proxy. When a domain is used, it needs to start with a period. A user can specify that both www.example.com
and foo.example.com should not use a proxy by setting The usage of the NetrcUnix introduced the curl supports A simple
Custom OutputTo better allow script programmers to get to know about the progress of curl, the To display the amount of bytes downloaded together with some text and an ending newline:
Kerberos FTP Transfercurl supports kerberos4 and kerberos5/GSSAPI for FTP transfers. You need the kerberos package installed and used at curl build time for it to be available. First, get the krb-ticket the normal way, like with the
There is no use for a password on the TELNETThe curl telnet support is basic and easy to use. curl passes all data passed to it on stdin to the remote server. Connect to a remote telnet server using a command line similar to:
Enter the data to pass to the server on stdin. The result is sent to stdout or to the file you specify with You might want the Pass options to the telnet protocol negotiation, by using the
Other interesting options for it
NOTE: The telnet protocol does not specify any way to login with a specified user and password so curl cannot do that automatically. To do that, you need to track when the login prompt is received and send the username and password accordingly. Persistent ConnectionsSpecifying multiple files on a single command line makes curl transfer all of them, one after the other in the specified order. libcurl attempts to use persistent connections for the transfers so that the second transfer to the same host can use the same connection that was already initiated and was left open in the previous transfer. This greatly decreases connection time for all but the first transfer and it makes a far better use of the network. Note that curl cannot use persistent connections for transfers that are used in subsequent curl invokes. Try to stuff as many URLs as possible on the same command line if they are using the same host, as that makes the transfers faster. If you use an HTTP proxy for file transfers, practically all transfers are persistent. Multiple Transfers With A Single Command LineAs is mentioned above, you can download multiple files with one command line by adding more URLs. If you want those to get saved to a local file instead of printed to stdout, you need to add one save option for each URL you specify. Note that this also goes for the For example: get two files and use
You can also upload multiple files in a similar fashion:
IPv6curl connects to a server with IPv6 when a host lookup returns an IPv6 address and fall back to IPv4 if the connection fails. The
When this style is used, the
IPv6 addresses provided other than in URLs (e.g. to the Mailing ListsFor your convenience, we have several open mailing lists to discuss curl, its development and things relevant to this. Get all info at https://curl.se/mail/. Please direct curl questions, feature requests and trouble reports to one of these mailing lists instead of mailing any individual. Available lists include:
|
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |