windows 批处理 FTP mget 命令不适用于通配符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16526350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:30:27  来源:igfitidea点击:

Batch FTP mget command not working with wildcard?

windowsbatch-file

提问by wjh

I have written a batch script that logs into my ftp server, then navigates to a directory. I am having trouble with the mget command, I want it to download every .dat file in the directory, but it simply returns this error:

我编写了一个批处理脚本,它登录到我的 ftp 服务器,然后导航到一个目录。我在使用 mget 命令时遇到问题,我希望它下载目录中的每个 .dat 文件,但它只是返回此错误:

Cannot access file '/home/minecraft/multicraft/servers/server267/world/players/*.dat':No such file or directory.
200 Type set to: ANSI
Cannot find list of remote files

Here is my script (ran from cmd)

这是我的脚本(从 cmd 运行)

open 66.71.244.202
USER
PASSWORD
cd /world
cd players
mget *.dat

采纳答案by joudifoul

When you execute your script file with ftp, you have to turn off the globbing which will allow the use of wildcards in the script. For example:

当您使用 ftp 执行脚本文件时,您必须关闭允许在脚本中使用通配符的通配符。例如:

ftp -n -i -s:scriptfile.txt 

should work but

应该工作但是

ftp -n -i -g -s:scriptfile.txt

will not.

将不会。

回答by Kash22

That is by design. The most recent update to the FTP specification (RFC 3659) explicitly forbids it (see section 2.2.2):

那是设计使然。FTP 规范 (RFC 3659) 的最新更新明确禁止它(参见第 2.2.2 节):

For the commands defined in this specification, all pathnames are to be treated literally. That is, for a pathname given as a parameter to a command, the file whose name is identical to the pathname given is implied. No characters from the pathname may be treated as special or "magic", thus no pattern matching (other than for exact equality) between the pathname given and the files present in the NVFS of the server-FTP is permitted.

Clients that desire some form of pattern matching functionality must obtain a listing of the relevant directory, or directories, and implement their own file name selection procedures.

回答by ips

I know this is old, but it might help someone. I had the same issue with wildcards on MGET from Windows FTP, but it was not consistent in that it worked talking to someremote systems, but not to allof them.

我知道这很旧,但它可能对某人有所帮助。我在 Windows FTP 的 MGET 上遇到了相同的通配符问题,但它不一致,因为它可以与某些远程系统通信,但不能与所有远程系统通信。

My script was doing this:

我的脚本是这样做的:

cd /folder/folder
mget ./-400TA/folder/*_XYZ

In the folder structure I have a set of different folders that begin with hyphens, and for whatever reason the script CD's down to just above there, and uses the relative path in the MGET. I had the same issue that some of you reported, that if I connected interactively and typed the commands one by one, it worked. But in batch, it didn't.

在文件夹结构中,我有一组以连字符开头的不同文件夹,无论出于何种原因,脚本 CD 都在那里,并使用 MGET 中的相对路径。我遇到了你们中一些人报告的同样问题,如果我以交互方式连接并一个一个输入命令,它就会起作用。但在批处理中,它没有。

I followed the suggestions in this and other posts, but no joy. I don't have access to the remote systems at the moment to look at them to figure out why some worked and some didn't.

我遵循了这篇文章和其他文章中的建议,但并不高兴。我目前无法访问远程系统,无法查看它们以找出为什么有些系统有效而有些无效。

However, what I did find was this. Changing my script as follows:

然而,我确实找到了这个。更改我的脚本如下:

cd /folder/folder/-400TA/folder
mget *_XYZ

did the trick. Simple. There's some strange interaction going on somewhere possibly with folder protections or something, but it just shows that trying out different things may get you there in the end.

成功了。简单的。某处可能发生了一些奇怪的交互,可能与文件夹保护或其他东西有关,但这只是表明尝试不同的东西可能会让您最终达到目标。

回答by Watchmaker

I would make sure glob is on, when turned off the file name in the put and get commands is taken literally and wildcards will not be looked at.

我会确保 glob 处于打开状态,当关闭 put 和 get 命令中的文件名时,会按字面意思执行,并且不会查看通配符。

More info:

更多信息:

glob:Toggle filename expansion for mdelete, mget and mput. If globbing is turned off with glob, the file name arguments are taken literally and not expanded. Globbing for mput is done as in csh. For mdelete and mget, each remote file name is expanded separately on the remote machine and the lists are not merged. Expansion of a directory name is likely to be different from expansion of the name of an ordinary file: the exact result depends on the foreign operating system and ftp server, and can be previewed by doing ‘mls remote-files -' Note: mget and mput are not meant to transfer entire directory subtrees of files. That can be done by transferring a tar archive of the subtree (in binary mode).

glob:切换 mdelete、mget 和 mput 的文件名扩展。如果使用 glob 关闭 globbing,则文件名参数将按字面意思进行而不是扩展。mput 的通配是在 csh 中完成的。对于 mdelete 和 mget,每个远程文件名在远程机器上单独展开,列表不会合并。目录名的扩展可能与普通文件名的扩展不同:具体结果取决于国外的操作系统和ftp服务器,可以通过'mls remote-files -'进行预览 注意:mget和mput 并不意味着传输文件的整个目录子树。这可以通过传输子树的 tar 存档(以二进制模式)来完成。

Once you are inside your ftp try to check the glob and set it on if it is off. The default behaviour is on, from the command line when connecting to ftp with the option -gyou can turn off the file name globbing.

一旦你进入你的 ftp 尝试检查 glob 并在它关闭时将其打开。默认行为是打开的,在连接到 ftp 时从命令行使用-g可以关闭文件名通配符的选项。

回答by Sven

It could very well also be a firewall issue where it is not permitting or forwarding the servers inbound connection. Happened to me.

它也很可能是防火墙问题,它不允许或转发服务器入站连接。发生在我身上。