How to list the sub directories in a Windows FTP server? - windows

I'm trying to list all the directories and sub directories in a windows server from Unix FTP command. I tried dir -r command but it only displays the directories in current folder. dir /s command is not displaying anything. I don't have utilities like winexe also. Any idea would greatly help me. Thanks in advance.

There's no command to list directories recursively in the common *nix ftp command-line client.
Some FTP servers (like ProFTPD) support switches to the LIST command (and similar). But that's a non-standard behavior that does not have any backing in the FTP specification/RFC.
You didn't specify what Windows FTP server you are using. Assuming IIS: The IIS does not support any switches at all, what is the correct behavior. It is a task for the client to do the recursion. But again, the common *nix ftp client does not support that.
Similar question:
Get a whole FTP directory listings recursively in one call possible to reduce time

Try dir -R. dir /s is a windows command, and dir -r is reversing the output order.

Related

Delete folder with large number of files

I want to delete a folder with large number of files (>100.000).
I only have FTP access. No SSH.
Do you have any ideas how to run commands via Terminal to delete? It seems to be impossible to do it with Filezilla.
You may use one of these console based ftp-clients:
General Unix:
NcFTP
Debian /Redhat:
yafc
Windows:
Just use the built in cmd and type:
ftp -? //for available commands
delete remote__file_name //for file deletion
rmdir directory_name //for dir deletion

Bash script for recursive directory listing on FTP server without -R

There are multiple folders with subfolders and image files on the FTP server. The -R is disabled. I need to dump the recursive directory listing with the path name in a text file. The logic I have till now is that, traverse in each folder, check the folder name if it consists of '.' to verify it as a file or a folder, if its a folder, go in and check for subfolders or files and list them. Since I cannot go with the -R, I have to go with a function to perform traverse each folder.
#!/bin/sh
ftp_host='1.1.1.1'
userName='uName'
ftp -in <<EOF
open $ftp_host
user $userName
recurList() {
path=`pwd`
level=()
for entry in `ls`
do
`cwd`
close
bye
EOF
I am stuck with the argument for the for loop!
Sorry to see you didn't get any replies yet. I think the reason may be that Bash isn't a good way to solve this problem, since it requires interacting with the FTP client, i.e. sending commands and reading responses. Bash is no good at that sort of thing. So there is no easy answer other than "don't use Bash".
I suggest you look at two other tools.
Firstly, you may be able to get the information you want using http://curlftpfs.sourceforge.net/. If you mount the FTP server using curlftpfs, then you can use the find command to dump the directory structure. This is the easiest option... if it works!
Alternatively, you could write a program using Python with the ftplib module: https://docs.python.org/2/library/ftplib.html. The module allows you to interact with the FTP server through API calls.

Batch FTP mget command not working with wildcard?

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
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.
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.
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.
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.
It could very well also be a firewall issue where it is not permitting or forwarding the servers inbound connection. Happened to me.

how to copy whole directories using FTP commands

Anyone know how to put whole directories from local to another server using FTP command?
i had use mput , but it just transfer file only.
cd /images_temp --> ws_ftp virtual folder name
mput *.IMG --> just transfer multiple file
anyone can teach me what command i need to use to transfer whole directories?
thanks
You can use mput * or mget *. Confirm with a rather than y. You can change the prompting behavior using the prompt command. You will find more information in the manual page. In a unix environment, man ftp
You can iterate and decent into directories and use mput *.IMG but that would probably inefficient. Consider using ncftpput where you can upload the directory remotely with just one line.

How to use GREP in FTP client where Destination Machine is Unix based

How to use GREP in FTP client where Destination Machine is Unix based?
I want to find files containing specific string amoung all files but i can not initiate telnet session. I can only initiate FTP session and needed to find files/string in various folders & subfolders. Kindly help.
grep is not part of the standard ftp commands. I'm afraid you'll have to make do with ls. As far as I know it doesn't support searching through subfolders though. See this thread for another client.

Resources