天天看点

23. CURL 常用命令通过 ——L 选项进行重定向下载指定时间内修改过的文件CURL 授权

23. CURL 常用命令

下载单个文件,默认将输出打印到标准输出(STDOUT)中

# curlhttp://localhost:8888/index.html

通过 -O/-o 选项保存下载的文件到指定的文件夹

-o:将文件保存为命令行中指定的文件名(就是重命名)

# curl -o index2.htmlhttp://localhost:8888/index.html

-O:使用 URL 中默认的文件名称保存文件到本地

# curl -O http://localhost:8888/index.html

同时获取多个文件

curl -O URL1   -O URL2

默认情况下CURL不会发送HTTP Location headers(重定向).当一个被请求页面移动到另一个站点时,

会发送一个HTTP Loaction header作为请求,然后将请求重定向到新的地址上

# curl -L http://localhost:8888/index.html

断点续传

-C:断点续传功能,已经下载过的文件不会被下载

# curl -C -O http://localhost:8888/index.html

对 CURL 使用网络限速

# curl --limit-rate 1000B -O http://localhost:8888/index.html

当下载一个文件时,可对该文件的最后修改日期进行判断,如果该文件在指定日期(2011-12-21)内修改过,就进行下载,否则不下载

# curl -z 21-Dec-11 http://localhost:8888/index.html

-u:在访问需要授权的页面时,可以指定用户名和密码,一般都只提供用户不提供密码,否则会在历史记录里被找到

# curl -u username:password http://localhost:8888/pub/index.html

从 FTP 服务器下载文件

# 列出 pub 路径下的所有文件和文件夹

# curl -u name:pass -O http://localhost:8888/pub/

# 下载 pub 路径下的 index.html 文件

# curl -u name:pass -O http://localhost:8888/pub/index.html

上传文件到 FTP 服务器

-T:上传本地文件到 FTP 服务器

# 上传单个文件到 FTP 服务器

# curl -u user:pass -T 1.txt http://localhost:8888/pub/index.html

# 上传多个文件到 FTP 服务器

# curl -u user:pass -T  "{file1, file2, file3}"  http://localhost:8888/pub/index.html

为 CURL 设置代理

# curl -x  proxysever.test.com:3128 http://localhost:8888/pub/index.html

保存与使用网站 cookie 信息

# 将网站的 cookie 保存到 1.txt 文件中

# curl -D 1.txt  http://localhost:8888/pub/index.html

# 将网站的cookies信息保存到sugarcookies文件中

curl -D sugarcookies http://localhost/sugarcrm/index.php

继续阅读