我正在尝试使用以下代码创建一个到 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);
问题是我的 ftp 服务器上的文件没有得到我请求的包含英语、希腊语和德语字符的名称 --> "δοκιμαστικό αρχείοüß-äCopy.txt
1)我能用它做什么?
更改区域设置后会有一些改进-> 非 Unicode 程序的当前语言为希腊语,但我仍然想念德语字符。
2)为什么ac#程序依赖这个设置?为了避免依赖此设置,我应该遵循一种特殊的方法吗?
编码噩梦再次出现:(