Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows wget上的转义字符--内容处置文件命名_Windows_Bash_Shell_Sh_Wget - Fatal编程技术网

Windows wget上的转义字符--内容处置文件命名

Windows wget上的转义字符--内容处置文件命名,windows,bash,shell,sh,wget,Windows,Bash,Shell,Sh,Wget,关于内容配置有很多问题,但没有一个能与我的问题相匹配。我希望这里有人能帮我解决这个问题 所以,我想用wget下载很多文件。我使用了--content-disposition参数来获得良好的文件命名。但不幸的是,当文件名有一些特殊字符时,如\,,/,:,,“,*,,文件下载会被转义 比方说,我要下载的文件名为Business Insider:How to Kickstart your business。正如您所注意到的,该文件名具有特殊字符:,当我运行脚本时,wget确实下载了该文件,但该文件名仅

关于内容配置有很多问题,但没有一个能与我的问题相匹配。我希望这里有人能帮我解决这个问题

所以,我想用wget下载很多文件。我使用了
--content-disposition
参数来获得良好的文件命名。但不幸的是,当文件名有一些特殊字符时,如
\
/
*
,文件下载会被转义

比方说,我要下载的文件名为Business Insider:How to Kickstart your business。正如您所注意到的,该文件名具有特殊字符
,当我运行脚本时,wget确实下载了该文件,但该文件名仅返回大小为零的Business Insider,并且没有任何文件名分机

我尝试了
--restrict file names=windows
和其他可用的选项,如
-O
和basename,但仍然没有成功

以下是脚本:

wget --content-disposition --referer=$url $dl
首先尝试此操作--restrict file names=nocontrol

如果这不起作用,那么对我来说这就起作用了:--restrict file names=unix(因为我在Linux机器上或在Windows中使用BASH/Cygwin)

您可能需要--restrict file names=windows

如果您注意到了,它现在将下载带有特殊字符的文件名

$ wget  --restrict-file-names=unix --content-disposition --referer=$url $dl
$ ls -l
total 17740
-rw-r--r-- 1 giga group 18163514 May 10  2014 iPhone: The Missing Manual, 4th Edition.pdf
wget的Man在此选项上显示为: --限制文件名=模式 更改在生成本地文件名期间在远程URL中找到的字符必须转义。受此选项限制的字符将转义,即替换为%HH, 其中HH是对应于受限字符的十六进制数。此选项还可用于强制所有字母大小写为小写或大写

       By default, Wget escapes the characters that are not valid or safe as part of file names on your operating system, as well as control characters that are typically unprintable.  This
       option is useful for changing these defaults, perhaps because you are downloading to a non-native partition, or because you want to disable escaping of the control characters, or you
       want to further restrict characters to only those in the ASCII range of values.

       The modes are a comma-separated set of text values. The acceptable values are unix, windows, nocontrol, ascii, lowercase, and uppercase. The values unix and windows are mutually
       exclusive (one will override the other), as are lowercase and uppercase. Those last are special cases, as they do not change the set of characters that would be escaped, but rather
       force local file paths to be converted either to lower- or uppercase.

       When "unix" is specified, Wget escapes the character / and the control characters in the ranges 0--31 and 128--159.  This is the default on Unix-like operating systems.

       When "windows" is given, Wget escapes the characters \, |, /, :, ?, ", *, <, >, and the control characters in the ranges 0--31 and 128--159.  In addition to this, Wget in Windows
       mode uses + instead of : to separate host and port in local file names, and uses @ instead of ? to separate the query portion of the file name from the rest.  Therefore, a URL that
       would be saved as www.xemacs.org:4300/search.pl?input=blah in Unix mode would be saved as www.xemacs.org+4300/search.pl@input=blah in Windows mode.  This mode is the default on
       Windows.

       **If you specify nocontrol, then the escaping of the control characters is also switched off. This option may make sense when you are downloading URLs whose names contain UTF-8
       characters, on a system which can save and display filenames in UTF-8 (some possible byte values used in UTF-8 byte sequences fall in the range of values designated by Wget as
       "controls").**

       The ascii mode is used to specify that any bytes whose values are outside the range of ASCII characters (that is, greater than 127) shall be escaped. This can be useful when saving
       filenames whose encoding does not match the one used locally.
默认情况下,Wget会转义操作系统上作为文件名的一部分无效或不安全的字符,以及通常不可打印的控制字符。此
选项对于更改这些默认值很有用,可能是因为您正在下载到非本机分区,或者是因为您想禁用对控制字符的转义,或者
希望进一步将字符限制为ASCII值范围内的字符。
模式是一组逗号分隔的文本值。可接受的值是unix、windows、nocontrol、ascii、小写和大写。unix和windows的值是相互关联的
排他性(一个将覆盖另一个),如小写和大写。最后一个是特殊情况,因为它们不会更改将转义的字符集,而是
强制将本地文件路径转换为小写或大写。
当指定“unix”时,Wget将转义0--31和128--159范围内的字符/和控制字符。这是类unix操作系统的默认值。
当给定“windows”时,Wget将转义0--31和128--159范围内的字符\、|、/、:、?、“、*”和控制字符。除此之外,Windows中的Wget
模式使用+代替:以本地文件名分隔主机和端口,并使用@代替?将文件名的查询部分与其余部分分开。因此,一个URL
将保存为www.xemacs.org:4300/search.pl?Unix模式下的input=blah将保存为www.xemacs.org+4300/search。pl@input=Windows模式下的blah。此模式是上的默认模式
窗户。
**如果指定nocontrol,则控制字符的转义也将关闭。当您下载名称包含UTF-8的URL时,此选项可能有意义
字符,在能够以UTF-8格式保存和显示文件名的系统上(UTF-8字节序列中使用的一些可能的字节值在Wget指定的值范围内,如
“控制”)**
ascii模式用于指定值超出ascii字符范围(即大于127)的任何字节都应转义。这在保存时很有用
编码与本地使用的编码不匹配的文件名。

您能分享一个我们可以测试的特定URL吗?@darnir只需将
$URL
更改为,将
$dl
更改为。链接上的文件标题是iPhone:Missing Manual,第四版。嗨,阿伦,我以前尝试过所有可能的
——限制文件名
参数,但仍然没有成功。也许你还有别的建议?或者用另一种方法来欺骗它?做这个。。这很容易。您知道如何从URL获取文件名吗?一旦你有了它,然后在“wget-O”$filename“$URL”中使用它,即wget-O“business Insider:How to Kickstart your business.pdf”$URL$DLWhen我运行这个:wget--restrict file names=nocontrol--content disposition--referer=。。。。它给了我文件。。满满的(它所做的唯一一件事是将带有任何特殊字符的文件名更改为其对应的HTML/代码,即更改为%3A。我正在Unix机器上尝试这一点OK,这在当时起到了预期的作用:wget--restrict file names=Unix--content disposition--referer=Im在使用Cygwin的Windows机器上运行相同的..Bash,并且它在我用我在Windows机器和Linux机器上得到的更新了答案