cURL

cURL是一个利用URL语法在 命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称cURL为下载工具。
cURL支援的通讯协定有 FTP、 FTPS、 HTTP、 HTTPS、 TFTP、 Telnet、 DICT、 FILE和 LDAP。
 
cURL有linux版和windows版
http://curl.haxx.se/download.html
 
 
最简单的用法:

    获得netscape's 网站网页:

          curl http://www.netscape.com/

    在FTP服务器获得README文件:

          curl ftp://ftp.funet.fi/README

    获得一个使用8000端口的web服务器网页:

          curl http://www.weirdserver.com:8000/

    获得一个FTP目录的镜象:

          curl ftp://cool.haxx.se/

    获得一个gopher服务器上的文档:

          curl gopher://gopher.funet.fi

    获得自定义目录的文件:

          curl dict://dict.org/m:curl

    一次获得2个文档:

          curl ftp://cool.haxx.se/ http://www.weirdserver.com:8000/

下载文件

    将一个WEB页保存到硬盘上,名字叫thatpage.html:

          curl -o thatpage.html http://www.netscape.com/

    下载index.html文件, -O是大写的字母o。 (如果没有文件名,将会出现错误):

          curl -O http://www.netscape.com/index.html

    下载2个文件:

          curl -O www.haxx.se/index.html -O curl.haxx.se/download.html

使用密码

FTP

     ftp服务器使用 名字+密码, 可能包括他们的URL:

          curl ftp://name:[email protected]:port/full/path/to/file

     或者用-u指定名字和密码

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

FTPS

     你也可以使用SSL选项.

HTTP

     HTTP的URL不支持名字+密码. 但Curl无论如何都支持ftp风格的接口。

          curl http://name:[email protected]/full/path/to/file

     或分别指定名字和密码,同样还是使用-u选项

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

     HTTP也许提供许多鉴别方法和 curl支持若干: 基础, Digest, NTLM 和 Negotiate. 没有哪个有效的使用方法, curl默认使用'基础'. 你可以询问curl以获得更多的保护。
     任何服务器都会提供url, 使用
     --anyauth.

     注意! 自从HTTP URLs 不支持用户名和密码, 当curl使用一个代理的时候,你不能使用这个风格. 你必须使用-u选项来读取.

HTTPS

     通常都用私人的证书, 说明如下.

GOPHER

     Curl 没有密码支持gopher.

PROXY

使用端口888代理下载一个文件,代理地址是my-proxy:

          curl -x my-proxy:888 ftp://ftp.leachsite.com/README

从一个http服务器下载一个文件,需要用户名和密码, 同样使用如上设置:

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

一些代理需要特别的验证. 用 -U 来设置:

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

See also the environment variables Curl support that offer further proxy
control.

RANGES

    一个客户只能请求一个连接或更多的连接. Curl支持-r标记.

    获得文件的前100 bytes:

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

    获得文件的末尾500 bytes:

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

    Curl 也支持简单的ftp文件. 你只能规定开始和停止的位置.

    获得ftp服务器上的readme的前100 bytes:

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

UPLOADING

FTP

    一个命令上传全部数据:

          curl -T - ftp://ftp.upload.com/myfile

    往一个站点上上传数据, 并且使用名字和密码

          curl -T uploadfile -u user:passwd ftp://ftp.upload.com/myfile

    往站点上上传一个本地文件, 并且也使用本地文件名:

          curl -T uploadfile -u user:passwd ftp://ftp.upload.com/

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

          curl -T localfile -a ftp://ftp.upload.com/remotefile

    Curl也支持穿过代理上传数据, 但服务器要支持才可以. 如果不支持, you can run curl in
    a fashion similar to:

          curl --proxytunnel -x proxy:port -T localfile ftp.upload.com

HTTP

    上传所有数据到一个http服务器:

          curl -T - http://www.upload.com/myfile

    注意:上传之前,你要确定HTTP服务器已给你上传的授权.

    For other ways to do http data upload, see the POST section below.

VERBOSE / DEBUG

    如果curl fails where it isn't supposed to, 如果服务器不让你进,
    if you can't understand the responses: 使用 -v 标记获得详细报告. Curl将输出许多发送和接受的信息
    order to let the user see all client-server interaction (but it won't show
    you the actual data).

          curl -v ftp://ftp.upload.com/

    获得curl更多的信息和资料, 使用--trace 或 --trace-ascii 选项:

          curl --trace trace.txt www.haxx.se


详细信息

    不同的协议供应不同的信息参考关于files/documents. 获得curl的详细文件, 你应该使用 -I/--head option. 它得到全部的HTTP and FTP的详细信息. HTTP的参考很多.

    For HTTP, you can get the header information (the same as -I would show)
    shown before the data by using -i/--include. Curl understands the
    -D/--dump-header option when getting files from both FTP and HTTP, and it
    will then store the headers in the specified file.

    Store the HTTP headers in a separate file (headers.txt in the example):

          curl --dump-header headers.txt curl.haxx.se

    Note that headers stored in a separate file can be very useful at a later
    time if you want curl to use cookies sent by the server. More about that in
    the cookies section.

REFERRER

    A HTTP request has the option to include information about which address
    that referred to 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.

          curl -e www.coolsite.com http://www.showme.com/

    NOTE: The referer field is defined in the HTTP spec to be a full URL.

USER AGENT

关于浏览器发送的http请求信息. Curl允许用命令制定. 发送一些用于欺骗服务器或cgi的信息.

    比如:

    curl -A 'Mozilla/3.0 (Win95; I)' http://www.nationsbank.com/

    其他命令:
      'Mozilla/3.0 (Win95; I)'       Netscape Version 3 for Windows 95
      'Mozilla/3.04 (Win95; U)'      Netscape Version 3 for Windows 95
      'Mozilla/2.02 (OS/2; U)'       Netscape Version 2 for OS/2
      'Mozilla/4.04 [en] (X11; U; AIX 4.2; Nav)'             NS for AIX
      'Mozilla/4.05 [en] (X11; U; Linux 2.0.32 i586)'        NS for Linux

    注意:Internet Explorer能自动调节:
      'Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)'      MSIE for W95

    Mozilla 使用User-Agent名字:
      'Konqueror/1.0'               KDE File Manager desktop client
      'Lynx/2.7.1 libwww-FM/2.14' Lynx command line browser

PROGRESS METER

    The progress meter exists to show a user that something actually is
    happening. The different fields in the output have the following meaning:

    % Total      % Received % Xferd    Average Speed            Time               Curr.
                                   Dload    Upload Total      Current    Left      Speed
    0    151M      0 38608      0       0     9406        0    4:41:43    0:00:04    4:41:39    9287

    From left-to-right:
     %               - 全部完成的百分比
     Total           - 总的字节
     %               - 已完成的百分比
     Received        - 已下载的字节
     %               - 上传的百分数
     Xferd           - 上传的字节数
     Average Speed
     Dload           - 下载速度
     Average Speed
     Upload          - 上传速度
     Time Total      - 需要的全部时间
     Time Current    - 从下载到现在的时间
     Time Left       - 预期需要的时间
     Curr.Speed      - 最后5秒的数据需要的时间 (the first
                     5 seconds of a transfer is based on less time of course.)

    The -# option will display a totally different progress bar that doesn't
    need much explanation!

你可能感兴趣的:(职场,curl,休闲)