connect下载使⽤curl在命令⾏中下载⽂件
使⽤curl在命令⾏中下载⽂件
linux下curl简单应⽤详解
(对curl命令的使⽤⽐较齐全)
cURL 讀取雙向 ssl 認證 Web Server 網⾴⽅式
若服务端要求客户端认证,需要将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
2、使⽤all.pem
使⽤-k,是不对服务器的证书进⾏检查,这样就不必关⼼服务器证书的导出问题了。
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 CAverify error:num=20:unable to get local issuer certificateverify return:0---Certificate chain 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.google 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 ..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!..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)
1. wget 使⽤ –no-check-certificate 参数
2. curl 使⽤ -k或者--insecure 参数
、
将来学习了多线程,可以改为多线程下载。
最简单的下载语法:
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 /physiobank/database/mitdb/103.dat
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
1 1904k 1 2308
2 0 0 3582 0 0:09:04 0:00:06 0:08:58 3556
curl --head <url>
获取下载⽂件的⼤⼩。例如:
C:\Windows\system32>curl --head /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>
连接超时时间设置。
curl -m <seconds> <url>
传输数据超时时间设置。例如:
C:\Windows\system32>curl -o E:\MIT_BIH_Arrhythmia_Database\104.dat -m 20 "/physiobank/database/mitdb/104.dat" % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
1 1904k 1 2016
2 0 0 95
3 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
更多命令请参考:
# !/usr/bin/env python
# Filename: down.py
# download files from /physiobank/database/mitdb/
import os
home = r"E:\MIT_BIH_Arrhythmia_Database"
fext = [".atr", ".dat", ".hea"]
hurl = r"/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)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论