FTP Error 553 - Filename not allowed using umlauts

311 views Asked by At

I've got a problem by uploading a file using C#: When I m trying to upload a file which contains german Umlauts (ä, ö, ü) in its path and/or filename, I m getting an the FTP-error 553 "filename not allowed".

I can upload files without umlauts without any problems. I ve checked, if the encoding is correct and utf-8 is enabled on my FTP. I dont really want to change any file which contains umlauts, so I hope there is something I can do here.

When I m uploading my files via Filezilla, everything is fine. There are also no problem to download or get those files. Only uploading them causes an error.

This works fine:

ftp://ftp.myurl.com/mainfolder/folder/filename [id].png

This will give me error 553:

ftp://ftp.myurl.com/mainfolder/folder/filenäme [id].png
ftp://ftp.myurl.com/mainfolder/földer/filename [id].png

Here is my source code:

            string fullpath = ftp.url + folder + "/" + file.name;
            fullpath = fullpath.Replace("ä", "%C3%A4").Replace("ü", "%C3%BC").Replace("ö", "%C3%B6").Replace(" ","%20");
            Uri uri = new Uri(fullpath);

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
            request.UseBinary = true;
            request.KeepAlive = false;
            request.UsePassive = false;
            request.Timeout = 10000;
            request.Method = WebRequestMethods.Ftp.UploadFile;

            request.Credentials = new NetworkCredential(Data.user, Data.password);

            FileStream fs = new FileStream(file.fullname, FileMode.Open, FileAccess.Read);
            BinaryReader sourceStream = new BinaryReader(fs, Encoding.UTF8);

            Stream requestStream = request.GetRequestStream();

            byte[] chunk;
            chunk = sourceStream.ReadBytes(1024);
            int totalLength = 0;
            while (chunk.Length > 0)
            {
                requestStream.Write(chunk, 0, chunk.Length);
                totalLength += chunk.Length;
                chunk = sourceStream.ReadBytes(1024);
            }
            requestStream.Close();
            sourceStream.Close();
            request.ContentLength = totalLength;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

            response.Close();
0

There are 0 answers