3
votes

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:

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)

open 66.71.244.202
USER
PASSWORD
cd /world
cd players
mget *.dat
5
Does it work when you run the commands manually, rather than from a batch file? - Vicky
Can you list your target files in that directory? - RobW
Along the same lines as Rob's question, can you just GET any 1 of the .dat files. If you can list the directory contents and you can GET any 1 of the files, you can dynamically build a script to use GET for all of the .dat files. If you can't do either, you don't have appropriate rights on the FTP server. - Matt Williamson
I CAN list the files, and I can get individual files too. It just doesnt like *'s. How would I do that dynamic thing? - wjh

5 Answers

6
votes

That is by design. The most recent update to the FTP specification (RFC 3659) explicitly forbids it (see section 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.
2
votes

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 -n -i -s:scriptfile.txt 

should work but

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

will not.

1
votes

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 some remote systems, but not to all of them.

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.

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.

0
votes

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.

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

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 -g you can turn off the file name globbing.

-1
votes

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