Using NLST to retrieve file names

S

stainless

I know this is not necessarily a C# question but the code I am
wrinting is C# and I wasn't sure whereelse to ask the question.

I have taken some web code (from codeproject.com) that performs FTP
commands and used this in C# code to retrieve a list of files in a
diretory, using the NLST command.

My command is :

SendCommand("NLST" + mask)

The mask, for example, is "FILE*.txt"

The idea is that this should retrieve a list of files that match the
mask.

The problem I have is that it only retrieves names that match the case
exactly.

eg. FILE001.txt is retrieved whereas file002.txt and FiLe003.Txt are
not.

I cannot guarantee the case of the filenames to be processed and thus,
am not sure that this code will be suitable. Is there some kind of
setting in my C# code that would ensure both file names are retrieved?

Cheers

Mark
 
N

Nicholas Paldino [.NET/C# MVP]

Mark,

RFC 959 isn't very specific about wildcards, or case-sensitive
comparisons for the NLST command in the FTP protocol. To that end, it is up
to the server to decide whether or not to perform a case-insensitive search
(or to use wildcards, for that matter).

If the server is not performing a case-insensitive search, you will have
to try all possible combinations of cases of all the letters in order to be
sure.

Or, you might want to just not use a mask and then compare the filenames
on the client side yourself (it's probably much, much easier and faster,
since the number of combinations of words which have all the possible mixed
cases grows exponentially with each letter in the word).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top