zoukankan      html  css  js  c++  java
  • OS + Linux/Unix download tools curl / wget

    s

     

    用wget下载整个网站

    http://zhangyafeikimi.iteye.com/blog/385353 

    wget下载整个网站 
    可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps , -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参数,因为如果你要下载的网站也有别的网站的链接,wget也会把别的网站的东西下载 下来,由于互联网的特性,很有可能你会把整个互联网给下载下来 --,所以要加上 -np这个参数,表示不下载别的站点的链接. -k表示将下载的网页里的链接修改为本地链接.-p获得所以显示网页所需的元素,比如图片什么的. 
    另外还有其他的一些参数可以使用: 

    -c表示断点续传 

    -t 100表示重试100次,-t 0表示无穷次重试 

    另外可以将要下载的url写到一个文件中,每个url一行,使用这样的命令 wget -i download.txt. 

    --reject=avi,rmvb 表示不下载avi,rmvb的文件,--accept=jpg,jpeg,表示只下载jpg,jpeg的文件. 

    可以在用户目录下建立一个.wgetrc的文件(windows里面好像不能直接建立这样的文件,windows会认为没有文件名--),里面写上 http-proxy = 123.456.78.9:80,然后在加上参数 --proxy=on,如果需要密码,再加上下面的参数 --proxy-user=username, --proxy-passwd=password

     

     

    mac curl 使用方法

    http://lijunjie.iteye.com/blog/395270

    http://mac.pcbeta.com/viewthread.php?tid=3230

    http://hi.baidu.com/beyond_javy/blog/item/5bdc1f33cf5a22f61a4cff8d.html

    [root@B2Cmonitor ~]# curl -V

    curl 7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Protocols: tftp ftp telnet dict ldap http file https ftps
    Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

    [root@B2Cmonitor ~]# curl --help
    Usage: curl [options...] <url>
    Options: (H) means HTTP/HTTPS only, (F) means FTP only
     -a/--append        Append to target file when uploading (F)
     -A/--user-agent <string> User-Agent to send to server (H)
        --anyauth       Pick "any" authentication method (H)
     -b/--cookie <name=string/file> Cookie string or file to read cookies from (H)
        --basic         Use HTTP Basic Authentication (H)
     -B/--use-ascii     Use ASCII/text transfer
     -c/--cookie-jar <file> Write cookies to this file after operation (H)
     -C/--continue-at <offset> Resumed transfer offset
     -d/--data <data>   HTTP POST data (H)
        --data-ascii <data>  HTTP POST ASCII data (H)
        --data-binary <data> HTTP POST binary data (H)
        --negotiate     Use HTTP Negotiate Authentication (H)
        --digest        Use HTTP Digest Authentication (H)
        --disable-eprt  Inhibit using EPRT or LPRT (F)
        --disable-epsv  Inhibit using EPSV (F)
     -D/--dump-header <file> Write the headers to this file
        --egd-file <file> EGD socket path for random data (SSL)
        --tcp-nodelay   Use the TCP_NODELAY option
     -e/--referer       Referer URL (H)
     -E/--cert <cert[:passwd]> Client certificate file and password (SSL)
        --cert-type <type> Certificate file type (DER/PEM/ENG) (SSL)
        --key <key>     Private key file name (SSL)
        --key-type <type> Private key file type (DER/PEM/ENG) (SSL)
        --pass  <pass>  Pass phrase for the private key (SSL)
        --engine <eng>  Crypto engine to use (SSL). "--engine list" for list
        --cacert <file> CA certificate to verify peer against (SSL)
        --capath <directory> CA directory (made using c_rehash) to verify
                        peer against (SSL)
        --ciphers <list> SSL ciphers to use (SSL)
        --compressed    Request compressed response (using deflate or gzip)
        --connect-timeout <seconds> Maximum time allowed for connection
        --create-dirs   Create necessary local directory hierarchy
        --crlf          Convert LF to CRLF in upload
     -f/--fail          Fail silently (no output at all) on HTTP errors (H)
        --ftp-create-dirs Create the remote dirs if not present (F)
        --ftp-method [multicwd/nocwd/singlecwd] Control CWD usage (F)
        --ftp-pasv      Use PASV/EPSV instead of PORT (F)
        --ftp-skip-pasv-ip Skip the IP address for PASV (F)
        --ftp-ssl       Try SSL/TLS for the ftp transfer (F)
        --ftp-ssl-reqd  Require SSL/TLS for the ftp transfer (F)
     -F/--form <name=content> Specify HTTP multipart POST data (H)
        --form-string <name=string> Specify HTTP multipart POST data (H)
     -g/--globoff       Disable URL sequences and ranges using {} and []
     -G/--get           Send the -d data with a HTTP GET (H)
     -h/--help          This help text
     -H/--header <line> Custom header to pass to server (H)
        --ignore-content-length  Ignore the HTTP Content-Length header
     -i/--include       Include protocol headers in the output (H/F)
     -I/--head          Show document info only
     -j/--junk-session-cookies Ignore session cookies read from file (H)
        --interface <interface> Specify network interface/address to use
        --krb4 <level>  Enable krb4 with specified security level (F)
     -k/--insecure      Allow connections to SSL sites without certs (H)
     -K/--config        Specify which config file to read
     -l/--list-only     List only names of an FTP directory (F)
        --limit-rate <rate> Limit transfer speed to this rate
        --local-port <num>[-num] Force use of these local port numbers

     -L/--location      Follow Location: hints (H)
        --location-trusted Follow Location: and send authentication even
                        to other hostnames (H)
     -m/--max-time <seconds> Maximum time allowed for the transfer
        --max-redirs <num> Maximum number of redirects allowed (H)
        --max-filesize <bytes> Maximum file size to download (H/F)
     -M/--manual        Display the full manual
     -n/--netrc         Must read .netrc for user name and password
        --netrc-optional Use either .netrc or URL; overrides -n
        --ntlm          Use HTTP NTLM authentication (H)
     -N/--no-buffer     Disable buffering of the output stream
     -o/--output <file> Write output to <file> instead of stdout
     -O/--remote-name   Write output to a file named as the remote file
     -p/--proxytunnel   Operate through a HTTP proxy tunnel (using CONNECT)
        --proxy-anyauth Pick "any" proxy authentication method (H)
        --proxy-basic   Use Basic authentication on the proxy (H)
        --proxy-digest  Use Digest authentication on the proxy (H)
        --proxy-ntlm    Use NTLM authentication on the proxy (H)
     -P/--ftp-port <address> Use PORT with address instead of PASV (F)
     -q                 If used as the first parameter disables .curlrc
     -Q/--quote <cmd>   Send command(s) to server before file transfer (F)
     -r/--range <range> Retrieve a byte range from a HTTP/1.1 or FTP server
        --random-file <file> File for reading random data from (SSL)
     -R/--remote-time   Set the remote file's time on the local output
        --retry <num>   Retry request <num> times if transient problems occur
        --retry-delay <seconds> When retrying, wait this many seconds between each
        --retry-max-time <seconds> Retry only within this period
     -s/--silent        Silent mode. Don't output anything
     -S/--show-error    Show error. With -s, make curl show errors when they occur
        --socks4 <host[:port]> Use SOCKS4 proxy on given host + port
        --socks5 <host[:port]> Use SOCKS5 proxy on given host + port
        --stderr <file> Where to redirect stderr. - means stdout
     -t/--telnet-option <OPT=val> Set telnet option
        --trace <file>  Write a debug trace to the given file
        --trace-ascii <file> Like --trace but without the hex output
        --trace-time    Add time stamps to trace/verbose output
     -T/--upload-file <file> Transfer <file> to remote site
        --url <URL>     Spet URL to work with
     -u/--user <user[:password]> Set server user and password
     -U/--proxy-user <user[:password]> Set proxy user and password
     -v/--verbose       Make the operation more talkative
     -V/--version       Show version number and quit
     -w/--write-out [format] What to output after completion
     -x/--proxy <host[:port]> Use HTTP proxy on given port
     -X/--request <command> Specify request command to use
     -y/--speed-time    Time needed to trig speed-limit abort. Defaults to 30
     -Y/--speed-limit   Stop transfer if below speed-limit for 'speed-time' secs
     -z/--time-cond <time> Transfer based on a time condition
     -0/--http1.0       Use HTTP 1.0 (H)
     -1/--tlsv1         Use TLSv1 (SSL)
     -2/--sslv2         Use SSLv2 (SSL)
     -3/--sslv3         Use SSLv3 (SSL)
        --3p-quote      like -Q for the source URL for 3rd party transfer (F)
        --3p-url        source URL to activate 3rd party transfer (F)
        --3p-user       user and password for source 3rd party transfer (F)
     -4/--ipv4          Resolve name to IPv4 address
     -6/--ipv6          Resolve name to IPv6 address
     -#/--progress-bar  Display transfer progress as a progress bar
    [root@B2Cmonitor ~]# curl ftp://bbs.s*****.com -v
    * About to connect() to bbs.s*****.com port 21
    *   Trying 192.168.119.129... connected
    * Connected to bbs.s*****.com (192.168.119.129) port 21
    < 220 (vsFTPd 2.0.5)
    > USER anonymous
    < 331 Please specify the password.
    > PASS curl_by_daniel@haxx.se
    < 530 Login incorrect.
    * Access denied: 530
    * Closing connection #0
    curl: (67) Access denied: 530

     

    curl 是一个传输文件 (上传/下载 )的命令行工具 ,

    它支持FTP , FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE 和 LDAP 等多种协议。

    在 Mac OS X 里已经预装了curl,我主要用它来下载文件。
    curl 基本用法,使用格式如下: curl [选项][下载地址 ]

    CURL? 嗯,说来话长了~~~~
    这东西现在已经是苹果机上内置的命令行工具之一了,可见其魅力之一斑
    1)
    二话不说,先从这里开始吧!
    curl http://www.yahoo.com
    回车之后,www.yahoo.com 的html就稀里哗啦地显示在屏幕上了~~~~~
    2)
    嗯,要想把读过来页面存下来,是不是要这样呢?
    curl http://www.yahoo.com > page.html
    当然可以,但不用这么麻烦的!
    用curl的内置option就好,存下http的结果,用这个option: -o
    curl -o page.html http://www.yahoo.com
    这样,你就可以看到屏幕上出现一个下载页面进度指示。等进展到100%,自然就OK咯
    3)
    什么什么?!访问不到?肯定是你的proxy没有设定了。
    使用curl的时候,用这个option可以指定http访问所使用的proxy服务器及其端口: -x
    curl -x 123.45.67.89:1080 -o page.html http://www.yahoo.com
    4)
    访问有些网站的时候比较讨厌,他使用cookie来记录session信息。
    像IE/NN这样的浏览器,当然可以轻易处理cookie信息,但我们的curl呢?.....
    我们来学习这个option: -D <-- 这个是把http的response里面的cookie信息存到一个特别的文件中去
    curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com
    这样,当页面被存到page.html的同时,cookie信息也被存到了cookie0001.txt里面了
    5)
    那么,下一次访问的时候,如何继续使用上次留下的cookie信息呢?要知道,很多网站都是靠监视你的cookie信息,
    来判断你是不是不按规矩访问他们的网站的。
    这次我们使用这个option来把上次的cookie信息追加到http request里面去: -b
    curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.yahoo.com
    这样,我们就可以几乎模拟所有的IE操作,去访问网页了!
    6)
    稍微等等~~~~~我好像忘记什么了~~~~~
    对了!是浏览器信息~~~~
    有些讨厌的网站总要我们使用某些特定的浏览器去访问他们,有时候更过分的是,还要使用某些特定的版本~~~~
    NND,哪里有时间为了它去找这些怪异的浏览器呢!?
    好在curl给我们提供了一个有用的option,可以让我们随意指定自己这次访问所宣称的自己的浏览器信息: -A
    curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com
    这样,服务器端接到访问的要求,会认为你是一个运行在Windows 2000上的IE6.0,嘿嘿嘿,其实也许你用的是苹果机呢!
    而"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"则可以告诉对方你是一台PC上跑着的Linux,用的是Netscape 4.73,呵呵呵
    7)
    另外一个服务器端常用的限制方法,就是检查http访问的referer。比如你先访问首页,再访问里面所指定的下载页,这第二次访问的 referer地址就是第一次访问成功后的页面地址。这样,服务器端只要发现对下载页面某次访问的referer地址不 是首页的地址,就可以断定那是个盗连了~~~~~
    讨厌讨厌~~~我就是要盗连~~~~~!!
    幸好curl给我们提供了设定referer的option: -e
    curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txt http://www.yahoo.com
    这样,就可以骗对方的服务器,你是从mail.yahoo.com点击某个链接过来的了,呵呵呵
    8)
    写着写着发现漏掉什么重要的东西了!----- 利用curl 下载文件
    刚才讲过了,下载页面到一个文件里,可以使用 -o ,下载文件也是一样。
    比如, curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
    这里教大家一个新的option: -O
    大写的O,这么用: curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
    这样,就可以按照服务器上的文件名,自动存在本地了!
    再来一个更好用的。
    如果screen1.JPG以外还有screen2.JPG、screen3.JPG、....、screen10.JPG需要下载,难不成还要让我们写一个script来完成这些操作?
    不干!
    在curl里面,这么写就可以了:
    curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
    呵呵呵,厉害吧?!~~~
    9)
    再来,我们继续讲解下载!
    curl -O http://cgi2.tky.3web.ne.jp/~/[001-201].JPG
    这样产生的下载,就是
    ~zzh/001.JPG
    ~zzh/002.JPG
    ...
    ~zzh/201.JPG
    ~nick/001.JPG
    ~nick/002.JPG
    ...
    ~nick/201.JPG
    够方便的了吧?哈哈哈
    咦?高兴得太早了。
    由于zzh/nick下的文件名都是001,002...,201,下载下来的文件重名,后面的把前面的文件都给覆盖掉了~~~
    没关系,我们还有更狠的!
    curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~/[001-201].JPG
    --这是.....自定义文件名的下载?
    --对头,呵呵!
    #1是变量,指的是这部分,第一次取值zzh,第二次取值nick
    #2代表的变量,则是第二段可变部分---[001-201],取值从001逐一加到201
    这样,自定义出来下载下来的文件名,就变成了这样:
    原来: ~zzh/001.JPG ---> 下载后: 001-zzh.JPG
    原来: ~nick/001.JPG ---> 下载后: 001-nick.JPG
    这样一来,就不怕文件重名啦,呵呵
    9)
    继续讲下载
    我们平时在windows平台上,flashget这样的工具可以帮我们分块并行下载,还可以断线续传。
    curl在这些方面也不输给谁,嘿嘿
    比如我们下载screen1.JPG中,突然掉线了,我们就可以这样开始续传
    curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG
    当然,你不要拿个flashget下载了一半的文件来糊弄我~~~~别的下载软件的半截文件可不一定能用哦~~~
    分块下载,我们使用这个option就可以了: -r
    举例说明
    比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 要下载(赵老师的电话朗诵
    我们就可以用这样的命令:
    curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
    curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
    curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
    curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3
    这样就可以分块下载啦。
    不过你需要自己把这些破碎的文件合并起来
    如果你用UNIX或苹果,用 cat zhao.part* > zhao.mp3就可以
    如果用的是Windows,用copy /b 来解决吧,呵呵
    上面讲的都是http协议的下载,其实ftp也一样可以用。
    用法嘛,
    curl -u name:passwd ftp://ip:port/path/file
    或者大家熟悉的
    curl ftp://name:passwd@ip:port/path/file
    10)
    说完了下载,接下来自然该讲上传咯
    上传的option是 -T
    比如我们向ftp传一个文件: curl -T localfile -u name:passwd ftp://upload_site:port/path/
    当然,向http服务器上传文件也可以
    比如 curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
    注意,这时候,使用的协议是HTTP的PUT method
    刚才说到PUT,嘿嘿,自然让老服想起来了其他几种methos还没讲呢!
    GET和POST都不能忘哦。
    http提交一个表单,比较常用的是POST模式和GET模式
    GET模式什么option都不用,只需要把变量写在url里面就可以了
    比如:
    curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345
    而POST模式的option则是 -d
    比如,curl -d "user=nickwolfe&password=12345" http://www.yahoo.com/login.cgi
    就相当于向这个站点发出一次登陆申请~~~~~
    到底该用GET模式还是POST模式,要看对面服务器的程序设定。
    一点需要注意的是,POST模式下的文件上的文件上传,比如
    <form method="POST" enctype="multipar/form-data" action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi">
    <input type=file name=upload>
    <input type=submit name=nick value="go">
    </form>
    这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:
    curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
    罗罗嗦嗦讲了这么多,其实curl还有很多很多技巧和用法
    比如 https的时候使用本地证书,就可以这样
    curl -E localcert.pem https://remote_server
    再比如,你还可以用curl通过dict协议去查字典~~~~~
    curl dict://dict.org/d:computer

     

    问题1:

    [davadmin@sctspreapp01 ~]$ curl -I 10.27.188.107:8080

    curl: (7) couldn't connect to host

    问题1解决

    80端口未开放。“couldn't connect to host” 这样的错误可能是主机不可到达,或者端口不可到达。ping OK只代表主机可以到达。端口不可到达可能是由于HTTP 服务器未启动或者监听在其他端口入8080上了。还有一个可能是防火墙没开放80端口的访问权限。

    本次问题1解决:

    apache 本地8080端口已经开通,外面机器telnet apache 8080端口不通,查看apache所在机器并停止防火墙iptables,ok。

    本次问题1解决过程:

    [root@sctspreapp01 ~]# service tptables stop

    [root@sctspreapp01 ~]# chkconfig iptables off

    [root@sctspreapp01 ~]# /opt/apache/bin/httpd -f /opt/apache/conf/httpd.conf -k restart

    end

  • 相关阅读:
    asp.net2.0中读取web.config数据库连接字符串2种方法
    C#中ArrayList类的使用方法
    Parameters.AddWithValue(“@参数”,value)方法
    cookie 和session 的区别详解 (出处:http://shiyangxt.cnblogs.com )
    Button与Submit调用前台与后台代码的方法
    SqlDataReader和DataSet的选择
    Session和Cookie的使用总结
    webconfig文件详解
    C# sqlDataReader区别Dataset
    SqlDataAdapter.Update()方法与SqlCommandBuilder
  • 原文地址:https://www.cnblogs.com/lindows/p/14390300.html
Copyright © 2011-2022 走看看