http://m.blog.csdn.net/blog/mayadong7349/7019208

使用curl在命令行中下载文件

linux下curl简单应用详解

http://blog.sina.com.cn/s/blog_4da051a60101drqv.html

(对curl命令的使用比较齐全)

http://blog.csdn.net/csfreebird/article/details/9237925

用curl访问HTTPS站点并登录

http://blog.csdn.net/sjin_1314/article/details/17392675

linux C libcurl https 使用

http://www.ichiayi.com/wiki/tech/curl_ssl

cURL 讀取雙向 ssl 認證 Web Server 網頁方式

CURL使用SSL证书访问HTTPS

http://blog.chinaunix.net/uid-192452-id-3954329.html

若服务端要求客户端认证,需要将pfx证书转换成pem格式

openssl pkcs12 -clcerts -nokeys -in cert.pfx -out client.pem    #客户端个人证书的公钥

openssl pkcs12 -nocerts -nodes -in cert.pfx -out key.pem #客户端个人证书的私钥

也可以转换为公钥与私钥合二为一的文件

openssl pkcs12 -in  cert.pfx -out all.pem -nodes                                   #客户端公钥与私钥,一起存在all.pem中

执行curl命令

1、使用client.pem+key.pem

curl -k --cert client.pem --key key.pem https://www.xxxx.com

2、使用all.pem

curl -k --cert all.pem  https://www.xxxx.com

使用-k,是不对服务器的证书进行检查,这样就不必关心服务器证书的导出问题了。

OpenSSL Verify return code: 20 (unable to get local issuer certificate)

http://stackoverflow.com/questions/11548336/openssl-verify-return-code-20-unable-to-get-local-issuer-certificate

yingc@yingc:~/work/public/solution$ openssl s_client -connect 74.125.128.139:443
CONNECTED(00000003)
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.google.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority

SSL-Session:
    Protocol  : TLSv1.1
    Cipher    : ECDHE-RSA-RC4-SHA
    Session-ID: 867D004577B0B77EA7ACE36EBEA8234C2BE21ABBEDA4A2B17CD9BEB9CA08E5F8
    Session-ID-ctx:
    Master-Key: 8C9F4C5E01512A14D6F062DE6BDF33F2032A85215C5449055D25D52151458B5380351D0C84D42215455320E4E2EC473D
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - 17 25 ea c9 98 a9 1d bd-35 01 ce 18 a2 87 ec ea   .%......5.......
    0010 - 29 19 21 fc 79 a3 e4 23-89 97 f2 52 88 1d d1 0c   ).!.y..#...R....
    0020 - 2f 69 4c 20 78 9c e4 73-e2 8c 71 aa fa 83 67 84   /iL x..s..q...g.
    0030 - 56 8e 1d 3b 55 03 3b ad-b5 bb 6b df 85 d1 a6 af   V..;U.;...k.....
    0040 - 19 a5 38 41 4a f9 8a 19-52 11 bd 68 e3 5b 47 15   ..8AJ...R..h.[G.
    0050 - 3a 84 52 af a4 81 db 90-82 db f2 9d 47 df 00 6f   :.R.........G..o
    0060 - c5 28 c4 ef 85 94 f0 72-fc 47 7f 38 4f 1f 48 3e   .(.....r.G.8O.H>
    0070 - 37 ba e1 0e 5c c6 62 05-62 8c 35 27 73 74 73 92   7...\.b.b.5'sts.
    0080 - 7a c1 a2 10 12 db b7 be-37 04 8a 56 f3 d1 58 75   z.......7..V..Xu
    0090 - df a3 ef 31                                       ...1

Start Time: 1388745557
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)

openssl s_client -CApath /etc/ssl/certs/ -connect 74.125.128.139:443

Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.1
    Cipher    : ECDHE-RSA-RC4-SHA
    Session-ID: 932BBA8E505C788ABD841F8FA94E685654264E1076A723C3AF8C6967744A1936
    Session-ID-ctx:
    Master-Key: A2BA6685C97FFD38906103B6AC7CC01BE017AC4D890D41E8167B5063EA9797C6395F3E01437754B7D9FF7726156C9F55
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - 17 25 ea c9 98 a9 1d bd-35 01 ce 18 a2 87 ec ea   .%......5.......
    0010 - 5d 6c 40 86 a9 e1 04 35-17 0c 06 ab 8d e1 9c aa   ]l@....5........
    0020 - 24 4c 13 af a0 6b fe e3-aa bf b0 38 64 67 5e 78   $L...k.....8dg^x
    0030 - aa f2 08 b2 74 06 ce 16-21 ab 53 e2 5b 22 3b 41   ....t...!.S.[";A
    0040 - 82 dc 11 d3 a5 1c 72 d9-17 11 f8 cc 3b 42 a7 91   ......r.....;B..
    0050 - 6d d2 0d 11 2a 0d 8b 25-50 5c e5 65 7a e8 44 d2   m...*..%P\.ez.D.
    0060 - 22 94 21 5b 8d dc b6 91-ba ee 09 95 f0 6b 75 1b   ".![.........ku.
    0070 - 90 bf 19 55 32 21 90 c4-70 c1 76 15 15 cb 9a 43   ...U2!..p.v....C
    0080 - e8 00 16 77 10 fc 7c a3-d6 8f 73 37 c9 2e b4 0e   ...w..|...s7....
    0090 - 07 d5 1d 90                                       ....

Start Time: 1388745845
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)

Curl和Wget访问HTTPS连接出现Unable to establish SSl connection错误

    1. wget 使用 –no-check-certificate 参数
    2. curl 使用 -k或者--insecure 参数

./curl -o aa.js https://s.ytimg.com/yts/jsbin/html5player-vf
lG49soT.js --cacert /dvb/ca-certificates.crt

curl: (60) SSL certificate problem, verify that the CA cert is:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

curl: curl是利用URL语法在命令行方式下工作的文件传输工具。 [百科: http://baike.baidu.com/view/1326315.htm]
官网: http://curl.haxx.se/
其中libcurl有C语言、Python接口(PyCurl: http://pycurl.sourceforge.net/)等等。 curl.exe也可以作为一个命令行下载工具。

将来学习了多线程, 可以改为多线程下载

最简单的下载语法:

curl -o [filename] <url>

例如:

Microsoft Windows [版本 6.0.6001]
版权所有 (C) 2006 Microsoft Corporation。保留所有权利。 C:\Windows\system32>curl -o E:\MIT_BIH_Arrhythmia_Database\103.dat http://physionet.org/physiobank/database/mitdb/103.dat
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
1 1904k 1 23082 0 0 3582 0 0:09:04 0:00:06 0:08:58 3556

这样子就从网页http://physionet.org/physiobank/database/mitdb/103.dat把文件103.dat下载到本地E盘E:\MIT_BIH_Arrhythmia_Database\103.dat

curl --head <url>

获取下载文件的大小。例如:

C:\Windows\system32>curl --head http://physionet.org/physiobank/database/mitdb/100.atr
HTTP/1.1 200 OK
Date: Mon, 28 Nov 2011 05:35:46 GMT
Server: Apache/2.2.17 (Fedora)
Last-Modified: Thu, 30 Jul 1992 01:21:18 GMT
ETag: "82c1c18-11ce-287fa5a2e9f80"
Accept-Ranges: bytes
Content-Length: 4558
Connection: close
Content-Type: application/octet-stream

curl --connect-timeout <seconds> <url>

(参考: http://blog.csdn.net/learnhard/article/details/5683703)

连接超时时间设置。

curl -m <seconds> <url>

传输数据超时时间设置。 例如:

C:\Windows\system32>curl -o E:\MIT_BIH_Arrhythmia_Database\104.dat  -m 20 "http://physionet.org/physiobank/database/mitdb/104.dat"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
1 1904k 1 20162 0 0 953 0 0:34:06 0:00:21 0:33:45 377
curl: (28) Operation timed out after 20000 milliseconds with 20162 out of 195000
0 bytes received

更多命令请参考:

http://blog.csdn.net/lizhitao/article/details/6039473

# !/usr/bin/env python
# Filename: down.py
# download files from http://physionet.org/physiobank/database/mitdb/ import os home = r"E:\MIT_BIH_Arrhythmia_Database"
fext = [".atr", ".dat", ".hea"]
hurl = r"http://physionet.org/physiobank/database/mitdb/" for ext in fext:
    for index in range(100, 234):
        fname  = str(index) + ext
        fsave  = home + os.path.sep + fname
        fget   = hurl + fname
        if False == os.path.isfile(fsave):
            command = "curl -o " + fsave + " " + fget
            os.system(command)

http://blog.csdn.net/sjin_1314/article/details/17392675

使用curl在命令行中下载文件的更多相关文章

  1. curl命令上传下载文件

    下载单个文件,默认将输出打印到标准输出中(STDOUT)中 curl http://www.centos.org 通过-o/-O选项保存下载的文件到指定的文件中: -o:将文件保存为命令行中指定的文件 ...

  2. 在命令行中如何访问Program Files文件夹(转)

    通常来说Program Files文件夹位于C盘,也就是C:\Program File.为了保证兼容性,在命令行中通常使用环境变量%ProgramFiles%来表示Program Files的具体路径 ...

  3. mysql中如何在命令行中,执行一个SQL脚本文件?

    需求描述: 在mysql数据库的使用中,有的时候,需要直接在shell的命令行中,执行某个SQL脚本文件, 比如,要初始化数据库,创建特定的存储过程,创建表等操作,这里进行一个基本的测试. 一般情况, ...

  4. Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件

    Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件 前面我写了一篇博文Shell 从日志文件中选择时间段内的日志输出到另一个文件,利用循环实现了我想要实现的内容. 但是用这个脚本的同 ...

  5. 在Linux命令行中以图形化窗口打开文件夹

    Linux 系统中也有类似的命令.Ubuntu 发行版的命令行中,我们可以使用 nautilus 命令来打开指定目录的图形化窗口界面.类似下面命令这样使用: nautilus /home/testPr ...

  6. 在 Linux/windows下 命令行中使用和执行 PHP 代码[交互式php]

    [注释]在ubuntu下,升级php到7.1版本,虽然提示的是Interactive mode enabled, 但实际上可以直接书写命令,和interactive shell效果一样. 一:wind ...

  7. linux下常用FTP命令 上传下载文件【转】

    1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密码 ...

  8. Python通过调用windows命令行处理sam文件

    Python通过调用windows命令行处理sam文件 以samtools软件为例 一.下载或者索取得到windows版本的samtools软件,解压后如下: 进入文件内部,有如下几个文件: 二.将s ...

  9. Java实现命令行中的进度条功能

    前言 最近在写一个命令行中的下载工具,既然是下载文件用的,那么实时显示下载进度是非常有必要的.因此,就有了这里对进度条的实现尝试. 预览图 还是先预览下效果图吧. 这里是cmd里面的效果,总体看着还行 ...

随机推荐

  1. GoAhead2.5移植到ARM教程

    1.下载GoAhead2.5 下载地址:https://github.com/embedthis/goahead/releases?after=v3.1.2 2.编译 先解压到虚拟机的/opt目录下, ...

  2. 小程序swiper 快速滑动闪屏

    bindchange: function(e){ if(e.detail.source == "touch") { this.setData({ current: current ...

  3. 小程序获取openid unionid session_key

    .wxml <button bindtap="paytap">授权</button> .js Page({ paytap: function () { va ...

  4. Automate Screen or Button Taps via Tasker : Simulating keypress events

    When using Tasker, sometimes we want to do some automation on screen e.g. screen or button taps. At ...

  5. sql 递归查询所有的下级

    --> 生成测试数据表: [tb] IF OBJECT_ID('[Users]') IS NOT NULL     DROP TABLE [Users] GO CREATE TABLE [Use ...

  6. C语言每日小练(四)——勇者斗恶龙

    勇者斗恶龙 你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(砍掉全部的头). 村里有m个骑士能够雇佣.一个能力值为x的骑士能够砍掉恶龙一个致敬不超过x的头,且须要支付x个金币. 怎样雇佣骑士 ...

  7. panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

    go的结构体中私有的属性, 即使反射也获取不到

  8. 用Qemu模拟vexpress-a9 (六) --- 多核

    环境介绍 Win7 64 + Vmware 11 + ubuntu14.04 32 u-boot 版本:u-boot-2015-04 Linux kernel版本:linux-3.16.y busyb ...

  9. VS2010 打包生成exe文件后 执行安装文件出现 TODO:&lt;文件说明&gt;已停止工作并已关闭

    一.VS2010 打包生成exe文件后  执行安装文件出现  TODO:<文件说明>已停止工作并已关闭 TODO: <文件说明>已停止工作 原因: 打包的时候在文件系统中建立了 ...

  10. python接口自动化24-有token的接口项目使用unittest框架设计

    获取token 在做接口自动化的时候,经常会遇到多个用例需要用同一个参数token,并且这些测试用例跨.py脚本了. 一般token只需要获取一次就行了,然后其它使用unittest框架的测试用例全部 ...