WGET或cURL获取保护文件

时间:2012-10-11 19:18:34

标签: linux bash curl wget

哪个是从远程网络服务器下载文件的最佳途径?除非通过特定的useragent,否则我想使用.htaccess拒绝所有下载。这是否必须通过cURL完成,或者WGET也可以这样做吗?

2 个答案:

答案 0 :(得分:3)

http://www.gnu.org/software/wget/manual/wget.html

  

' - U agent-string'   “--user剂=剂字符串”   标识为http服务器的代理字符串。   http协议允许客户端使用User-Agent头字段来标识自己。这使得能够区分www软件,通常用于统计目的或跟踪协议违规。 Wget通常标识为“Wget / version”,版本是Wget的当前版本号。

     

但是,已知一些站点根据User-Agent提供的信息强制定制输出的策略。虽然这在理论上并不是一个坏主意,但它已经被服务器滥用,而不是(历史上)Netscape或者更常见的是Microsoft Internet Explorer。此选项允许您更改Wget发出的User-Agent行。不鼓励使用此选项,除非您确实知道自己在做什么。

     

使用'--user-agent =""'指定空用户代理,指示Wget不在http请求中发送User-Agent标头。

答案 1 :(得分:0)

另外,对于记录,来自man curl(1)

   -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.

          If this option is used several times, the last one will be used.