curl的用法 (1)
curl ( )是一个超强的命令行的http/httpsftp/sftp下载工具,甚至支持telnet协议。

curl支持proxy, http range, password, http cookie, http POST等任何浏览器能干的事情。



Get the main page from Netscape's web-server:


Get the README file the user's home directory at funet's ftp-server:


Get a web page from a server using port 8000:


Get a list of a directory of an FTP site:


Get the definition of curl from a dictionary:

curl dict://

Fetch two documents at once:


Get a file off an FTPS server:

curl ftps://

or use the more appropriate FTPS way to get the same file:

curl —ftp-ssl

Get a file from an SSH server using SFTP:

curl -u username s

Get a file from an SSH server using SCP using a private key to authenticate:

curl -u username: —key ~/.ssh/id_dsa —pubkey ~/.ssh/ \


Get a web page and store in a local file:

curl -o thatpage.html

Get a web page and store in a local file, make the local file get the name
of the remote document (if no file name part is specified in the URL, this
will fail):

curl -O

Fetch two files and store them with their remote names:

curl -O -O



To ftp files using name+passwd, include them in the URL like:

curl ftp://name:passwd@machine.domain:port/full/path/to/file

or specify them with the -u flag like

curl -u name:passwd ftp://machine.domain:port/full/path/to/file


It is just like for 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 —ftp-ssl option.


Curl also supports user and password in HTTP URLs, thus you can pick a file

curl http://name:passwd@machine.domain/full/path/to/file

or specify user and password separately like in

curl -u name:passwd http://machine.domain/full/path/to/file

HTTP offers many different methods of authentication and curl supports
several: Basic, Digest, NTLM and Negotiate. 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! Since HTTP URLs don't support user and password, you can't use that
style when using Curl via a proxy. You _must_ use the -u style fetch
during such circumstances.


Probably most commonly used with private certificates, as explained below.


Get an ftp file using a proxy named my-proxy that uses port 888:

curl -x my-proxy:888

Get a file from a HTTP server that requires user and password, using the
same proxy as above:

curl -u user:passwd -x my-proxy:888 http://www.get.this/

Some proxies require special authentication. Specify by using -U as above:

curl -U user:passwd -x my-proxy:888 http://www.get.this/

curl also supports SOCKS4 and SOCKS5 proxies with —socks4 and —socks5.

See also the environment variables Curl support that offer further proxy


With HTTP 1.1 byte-ranges were introduced. Using this, a client can request
to get only one or more subparts of a specified document. Curl supports
this with the -r flag.

Get the first 100 bytes of a document:

curl -r 0-99 http://www.get.this/

Get the last 500 bytes of a document:

curl -r -500 http://www.get.this/

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:

curl -r 0-99 ftp://www.get.this/README



Upload all data on stdin to a specified ftp site:

curl -T -

Upload data from a specified file, login with user and password:

curl -T uploadfile -u user:passwd

Upload a local file to the remote site, and use the local file name remote

curl -T uploadfile -u user:passwd

Upload a local file to get appended to the remote file using ftp:

curl -T localfile -a

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:

curl —proxytunnel -x proxy:port -T localfile


Upload all data on stdin to a specified http site:

curl -T -

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.


If curl fails where it isn't supposed to, if the servers don't let you in,
if you can't understand the responses: use the -v flag to get verbose
fetching. Curl will output lots of info and what it sends and receives in
order to let the user see all client-server interaction (but it won't show
you the actual data).

curl -v

To get even more details and information on what curl does, try using the
—trace or —trace-ascii options with a given file name to log to, like

curl —trace trace.txt