Ftp使用utf-8字符创建文件名,例如希腊语,德语等

ilt*_*rtz 4 c# ftp encoding utf-8

我正在尝试使用以下代码创建一个文件到ftp服务器(我也尝试使用UseBinary选项true和false)

string username = "name";
string password = "password";
string remotefolder = "ftp://ftp.myhost.gr/public_html/test/";
string remoteFileName = "??????????? ??????üß-äCopy.txt";
string localFile = @"C:\test\??????????? ?????? - Copy.txt";
String ftpname = "ftp://ftp.myhost.gr/public_html/test" + @"/" + Uri.EscapeUriString(Program.remoteFileName);


FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpname);
request.Proxy = null;
request.Credentials = new NetworkCredential(username, password);


request.UsePassive = true;
request.KeepAlive = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UseBinary = true;
//request.UseBinary = false;

 byte[] content = System.IO.File.ReadAllBytes(localFile);
 byte[] fileContents = new Byte[content.Length];

 Array.Copy(content, 0, fileContents, 0, content.Length);

 using (Stream uploadStream = request.GetRequestStream())
 {
     int contentLength = fileContents.Length;
     uploadStream.Write(fileContents, 0, contentLength);
 }

 FtpWebResponse response = (FtpWebResponse)request.GetResponse();
 Console.WriteLine(response.ExitMessage);
Run Code Online (Sandbox Code Playgroud)

问题是我的ftp服务器上的文件没有得到我要求的名称,其中包含英语,希腊语和德语字符 - >"δοκιμαστικόαρχείοüß-äCopy.txt

1)我能做些什么?

一旦我改变了我的区域设置 - >非Unicode程序的当前语言到希腊语,但我仍然想念德语字符,这有一些改进.

2)为什么ac#程序依赖于此设置?我是否应遵循特殊的方法以避免依赖此设置?

编码噩梦再次出现:(

Art*_*tur 8

仅将字符串编码为UTF8并将其作为文件名发送到FTP服务器是不够的.在过去,所有FTP服务器都只理解ASCII,现在为了保持向后兼容性 - 即使它们是Unicode识别的 - 当它们启动时它们也将所有文件也视为ASCII.

为了使一切顺利,您(您的程序)必须首先检查您的服务器能够做什么.客户端连接后服务器发送其功能 - 在您的情况下,您必须检查FEAT UTF8.如果你的服务器发送 - 它意味着它理解UTF8.尽管如此 - 即使它理解它 - 您必须明确告诉它,从现在开始,您将发送您的文件名UTF8编码,现在它是您的程序缺少的东西(因为您的服务器支持utf8,如您所述).

您的客户端必须向FTP服务器发送以下OPTS UTF8 ON.发送之后,您可以使用UTF8或对您的服务器说UTF8-ish(可以这么说).

请阅读此处了解详细信息文件传输协议的国际化