【发布时间】:2013-11-12 16:49:09
【问题描述】:
我正在尝试使用以下代码将文件创建到 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) 为什么 c# 程序依赖于这个设置?为了避免依赖此设置,我应该遵循一种特殊的方法吗?
编码噩梦再次出现:(
【问题讨论】:
-
“问题是我的 ftp 服务器上的文件没有得到我请求的名称” FTP 协议是否支持 Unicode?你的服务器软件呢?
-
我认为不是。但是因为我可以从 cpanel 完成,最有趣的是从 filezilla (使用强制 utf-8 选项),那么我认为我应该能够通过 C# 完成它..
-
您使用的是什么 FTP-Server 软件?
-
好吧,我不拥有服务器。我唯一知道的是它是 Linux 操作系统
-
您是否尝试更改编码,例如How to Answer[1] [1]:stackoverflow.com/questions/3369863/…