0

My program connects to an ftp server and list all the file that are in the specific folder c:\ClientFiles... The issue I'm having is that the files name have some funny character like – i.e. Billing–File.csv, but code removes replace these characters with a dash "-". When I try downloading the files its not found.

I've tried all the encoding types that are in the class Encoding but not is able to accommodate these character.

Please see my code listing the files.

        UriBuilder ub;
        if (rootnode.Path != String.Empty) ub = new UriBuilder("ftp", rootnode.Server, rootnode.Port, rootnode.Path);
        else ub = new UriBuilder("ftp", rootnode.Server, rootnode.Port);
        String uristring = ub.Uri.OriginalString;
        req = (FtpWebRequest)FtpWebRequest.Create(ub.Uri);
        req.Credentials = ftpcred;
        req.UsePassive = pasv;
        req.Method = WebRequestMethods.Ftp.ListDirectoryDetails;            
        try
        {
            rsp = (FtpWebResponse)req.GetResponse();
            StreamReader rsprdr = new StreamReader(rsp.GetResponseStream(), Encoding.UTF8); //this is where the problem is.

Your help or advise will be highly appreciated

2 Answers 2

1

Not every encoding has a class in the encoding namespace. You can get a list of all encodings know in your system by using:

 Encoding.GetEncodings()

(MSDN info for GetEncodings).

If you know what the name of the file should be, you can iterate through the list and see what encodings result in the correct filename.

Sign up to request clarification or add additional context in comments.

Comments

1

Try:

StreamReader rsprdr = new StreamReader(rsp.GetResponseStream(), Encoding.GetEncodings(1251)) ;

You may also try "iso-8859-1" instead of 1251

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.