跳至主要内容

【转】cURL 中文用户手册

Joomla! 开源天空  作者:web20  2008-09-02 23:52
  • 摘要:本文翻译了部分curl的用户手册

NAME

curl - transfer a URL

 语法

   curl [options] [URL...]

描述

      curl是一个向服务器或者从服务器下载数据的传输工具,它支持HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE等协议,这个命令设计为不需要用户的干预来执行。

     curl提供了非常多有用的功能,比如代理支持,用户认证,HTTP POST ,FTP Upload,断点续传等等,接下来你会看到,多的会是你头晕目眩。

     curl所有传输相关功能都基于libcurl ,详细信息请看 libcurl 3

URL

     url 语法遵循协议,RFC 3986中你可以看到详细的内容。

     http://site.{one,two,three}.com  你可以指定多个url,或者通过用大括号设置url中的一部分而设定url集合

     ftp://ftp.numericals.com/file[1-100].txt  ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)  ftp://ftp.letters.com/file[a-z].txt

     同样你可以采用数字字母的序列来指定一系列url,你可以混合使用这两种方式,比如 http://any.org/archive[1996-1999]/vol[1-4]/part{a,b,c}.html

    在命令行中可以指定任意数量的url,这些url可以按指定顺序逐一获得。

     curl 7.15.1版本以后,你可以指定步长,

 http://www.numericals.com/file[1-100:10].txt  http://www.letters.com/file[a-z:2].txt

     如果未指定协议前缀,curl将猜测协议,默认是http,但是将根据host名称猜测协议。如果host以ftp开头,那么curl将采用ftp协议。

     curl在多文件下载是将重用链接,这将提高速度,当然前提是这些文件是在一个命令行中。

进度提示

curl通常在执行过程中显示一个进度条,显示传输的数据量,传输速度,和剩余估计时间等。

可以,由于curl默认在终端显示传输回来的数据,如果你用curl做一个在终端返回数据的操作,那么curl将禁止在终端显示进度,否则的话,进度条就会与返回数据混淆在一起。

如果你想看到http post,put 这样操作的进度条,那么你就需要将返回的数据输出在文件中,输出可以通过redirect 操作 > 或者 -o 参数来进行。

如果你不想使用默认的进度条,那么可以使用 -#参数设置。

-a/--append

(FTP) When used in an FTP upload, this will tell curl to append to the target file instead of overwriting it. If the file doesn't exist, it will be created.

当使用ftp协议上传的时候,这个参数将使curl追加在目标文件,而不是覆盖它,如果目标文件不存在,将创建它。

If this option is used twice, the second one will disable append mode again.

如果在一个命令行重复使用了这个参数,第二个将不会是追加模式。

-A/--user-agent <agent string>

(HTTP) Specify the User-Agent string to send to the HTTP server. Some badly done CGIs fail if this field isn't set to "Mozilla/4.0". To encode blanks in the string, surround the string with single quote marks. This can also be set with the -H/--header option of course.

HTTP协议指定User-Agent并发送到http服务器,也可以通过-H参数进行设置。一些CGI如果这个域不填入 "Mozilla/4.0"就不能正确返回。如果字符串中有空格,请用单引号包含字串。

If this option is set more than once, the last one will be the one that's used.

如果多次指定这个参数,将使用最后一次的设定。

--anyauth

(HTTP) Tells curl to figure out authentication method by itself, and use the most secure one the remote site claims it supports. This is done by first doing a request and checking the response-headers, thus inducing an extra network round-trip. This is used instead of setting a specific authentication method, which you can do with --basic, --digest, --ntlm, and --negotiate.

Note that using --anyauth is not recommended if you do uploads from stdin, since it may require data to be sent twice and then the client must be able to rewind. If the need should arise when uploading from stdin, the upload operation will fail.

If this option is used several times, the following occurrences make no difference.

-b/--cookie <name=data>

(HTTP) Pass the data to the HTTP server as a cookie. It is supposedly the data previously received from the server in a "Set-Cookie:" line. The data should be in the format "NAME1=VALUE1; NAME2=VALUE2".

http传输cookie给服务器,这些数据可能是前次从服务器Set-Cookie行返回的,数据的格式应该是 NAME1=VALUE1;NAME2=VALUES2

If no '=' letter is used in the line, it is treated as a filename to use to read previously stored cookie lines from, which should be used in this session if they match. Using this method also activates the "cookie parser" which will make curl record incoming cookies too, which may be handy if you're using this in combination with the -L/--location option. The file format of the file to read cookies from should be plain HTTP headers or the Netscape/Mozilla cookie file format.

如果没有等号,curl就会把NAme作为前次存贮cookie的文件名。 

NOTE that the file specified with -b/--cookie is only used as input. No cookies will be stored in the file. To store cookies, use the -c/--cookie-jar option or you could even save the HTTP headers to a file using -D/--dump-header!

注意,这个参数仅仅作为输入,没有cookie会存贮到文件中,为了保存cookie,请使用 -c/--cookie-jar参数,或者你可以使用 -D/--dump-header参数将整个头保存到文件中

If this option is set more than once, the last one will be the one that's used.

如果重复使用这个参数,将使用最后一次设置

-B/--use-ascii

Enable ASCII transfer when using FTP or LDAP. For FTP, this can also be enforced by using an URL that ends with ";type=A". This option causes data sent to stdout to be in text mode for win32 systems.

在FTP和LDAP协议时候,传输采用ASCII传输方式。

If this option is used twice, the second one will disable ASCII usage.

如果重复使用这个参数,第二个将不能使用ascii方式。

--basic

(HTTP) Tells curl to use HTTP Basic authentication. This is the default and this option is usually pointless, unless you use it to override a previously set option that sets a different authentication method (such as --ntlm, --digest and --negotiate).

If this option is used several times, the following occurrences make no difference.

--ciphers <list of ciphers>

(SSL) 指定链接使用的密码. 必须使用合法的加密方式, 要了解密码的详细内容,请看这个地址: http://www.openssl.org/docs/apps/ciphers.html

多次使用这个参数,最后一个参数有效

--compressed

(HTTP) 请求一个压缩方式的相应,返回非压缩的文档. 如果服务器返回一个不支持的压缩方式,curl将报错。

如果这个参数使用多次,那么每次出现将反转这个参数状态。

--connect-timeout <seconds>

与服务器建立链接的最长时间限制,只限制链接阶段,一但建立了链接,这个参数就不起作用了。See also the -m/--max-time option.

多次使用这个参数,最后一个参数有效

-c/--cookie-jar <file name>

指定curl将cookie写入的文件,curl将从远程服务器得到的所有cookie写入。如果没有cookie,文件不会生成,cookie的写入格式是Netscape格式。如果设定文件名 "-",cookie写入到标准输出。 

注意如果cookie包不能建立或者写入,curl将不会报错或者失败,用 -v选项,会有一个警告显示,但这是唯一的可见反馈。

多次使用这个参数,最后一个参数有效

-C/--continue-at <offset>

指定在指定偏移地址恢复或继续文件传输。 

多次使用这个参数,最后一个参数有效

--create-dirs

与-o参数一起使用的时候,curl将创建必要的本地目录结构。 

FTP or SFTP 要创建远程目录, 请用 --ftp-create-dirs.

--crlf

(FTP) 上床过程中,将cr转换为crlf。

多次使用这个参数,近第一个起作用

-d/--data <data>

(HTTP) POST数据到服务器,与用户填写form并按按钮提交的效果一样。传输的mime type content-type application/x-www-form-urlencoded

-d/--data 与 --data-ascii 相同. 如果要post 二进制数据,应该用--data-binary option. 如果要post URL encode 的一个表单项,应该采用 --data-urlencode.

多次使用这个参数,将合并一起提交,比如 using '-d name=daniel -d skill=lousy' ,那么将post数据是'name=daniel&skill=lousy'

如果要post一个文件,以字符@开头,文件的内容必须是已经 urlencode编码的。比如要post文件 foobar,那么格式是 --data @foobar 

--data-binary <data>

(HTTP) post二进制数据

如果要post一个文件,以字符@开头

--data-urlencode <data>

(HTTP) 与 --data 参数相同,唯一的差别是要采用urlencode编码

--digest

(HTTP) 允许HTTP Digest 认证

--disable-eprt

(FTP) 禁用 EPRT and LPRT 命令 。

--disable-epsv

(FTP) 禁用 EPSV 命令

-D/--dump-header <file>

把完整的响应的头部写入文件.

 

评论

此博客中的热门博文

【转】VxWorks中的地址映射

在运用嵌入式系统VxWorks和MPC860进行通信系统设计开发时,会遇到一个映射地址不能访问的问题。 缺省情况下,VxWorks系统已经进行了如下地址的映射:   memory地址、bcsr(Board Control and Status)地址、PC_BASE_ADRS(PCMCIA)地址、Internal Memory地址、rom(Flach memory)地址等,但是当你的硬件开发中要加上别的外设时,如(falsh、dsp、FPGA等),对这些外设的访问也是通过地址形式进行读写,如果你没有加相应的地址映射,那么是无法访问这些外设的。   和VxWorks缺省地址映射类似,你也可以进行相应的地址映射。   如下是地址映射原理及实现:   1、 地址映射结构 在Tornado\target\h\vmLib.h文件中 typedef struct phys_mem_desc { void *virtualAddr; void *physicalAddr; UINT len; UINT initialStateMask; /* mask parameter to vmStateSet */ UINT initialState; /* state parameter to vmStateSet */ } PHYS_MEM_DESC; virtualAddr:你要映射的虚拟地址 physicalAddr:硬件设计时定义的实际物理地址 len;要进行映射的地址长度 initialStateMask:可以初始化的地址状态: 有如下状态: #define VM_STATE_MASK_VALID 0x03 #define VM_STATE_MASK_WRITABLE 0x0c #define VM_STATE_MASK_CACHEABLE 0x30 #define VM_STATE_MASK_MEM_COHERENCY 0x40 #define VM_STATE_MASK_GUARDED 0x80 不同的CPU芯片类型还有其特殊状态 initialState:实际初始化的地址状态: 有如下状态: #define VM_STATE_VALID 0x01 #define VM_STATE_VALID_NOT 0x00 #define VM_STATE_WRITA

【转】cs8900网卡的移植至基于linux2.6内核的s3c2410平台

cs8900网卡的移植至基于linux2.6内核的s3c2410平台(转) 2008-03-11 20:58 硬件环境:SBC-2410X开发板(CPU:S3C2410X) 内核版本:2.6.11.1 运行环境:Debian2.6.8 交叉编译环境:gcc-3.3.4-glibc-2.3.3 第一部分 网卡CS8900A驱动程序的移植 一、从网上将Linux内核源代码下载到本机上,并将其解压: #tar jxf linux-2.6.11.1.tar.bz2 二、打开内核顶层目录中的Makefile文件,这个文件中需要修改的内容包括以下两个方面。 (1)指定目标平台。 移植前:         ARCH?= $(SUBARCH) 移植后: ARCH            :=arm (2)指定交叉编译器。 移植前: CROSS_COMPILE ?= 移植后: CROSS_COMPILE   :=/opt/crosstool/arm-s3c2410-linux-gnu/gcc-3.3.4-glibc-2.3.3/bin/arm-s3c2410-linux-gnu- 注:这里假设编译器就放在本机的那个目录下。 三、添加驱动程序源代码,这涉及到以下几个方面。(1)、从网上下载了cs8900.c和cs8900.h两个针对2.6.7的内核的驱动程序源代码,将其放在drivers/net/arm/目录下面。 #cp cs8900.c ./drivers/net/arm/ #cp cs8900.h ./drivers/net/arm/ 并在cs8900_probe()函数中,memset (&priv,0,sizeof (cs8900_t));函数之后添加如下两条语句: __raw_writel(0x2211d110,S3C2410_BWSCON); __raw_writel(0x1f7c,S3C2410_BANKCON3); 注:其原因在"第二部分"解释。 (2)、修改drivers/net/arm/目录下的Kconfig文件,在最后添加如下内容: Config ARM_CS8900    tristate "CS8900 support" depends on NET_ETHERNET && A

【转】多迷人Gtkmm啊

前边已经说过用glade设计界面然后动态装载,接下来再来看看怎么改变程序的皮肤(主题)     首先从 http://art.gnome.org/themes/gtk2 下载喜欢的主题,从压缩包里提取gtk-2.0文件夹让它和我们下边代码生成的可执行文件放在同一个目录下,这里我下载的的 http://art.gnome.org/download/themes/gtk2/1317/GTK2-CillopMidnite.tar.gz     然后用glade设计界面,命名为main.glade,一会让它和我们下边代码生成的可执行程序放在同一个目录下边     然后开始写代码如下: //main.cc #include <gtkmm.h> #include <libglademm/xml.h> int main(int argc, char *argv[]) {     Gtk::Main kit(argc,argv);         Gtk::Window *pWnd;        gtk_rc_parse("E:\\theme-viewer\\themes\\gtk-2.0\\gtkrc");       Glib::RefPtr<Gnome::Glade::Xml> refXml;     try     {         refXml = Gnome::Glade::Xml::create("main.glade");     }     catch(const Gnome::Glade::XmlError& ex)     {         Gtk::MessageDialog dialog("Load glade file failed!", false,       \                                   Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);         dialog.run();               return 1;     }         refXml->get_widget("main", pWnd);     if(pW