上传到ftp服务器后,文件名显示错误编码

时间:2014-04-20 10:45:08

标签: c# wpf ftp

将文件上传到ftp服务器后,文件名显示为????????。文件名包含西里尔字。但是这个文件内部显示正确。应该怎么做才能显示正确的文件名?我的代码在这里:

        FileInfo fileInfo = new FileInfo(filepath);
        string fileName = fileInfo.Name.ToString();
        WebRequest requestFTP = WebRequest.Create(IncomingFtpPath + fileName);

        requestFTP.Credentials = new NetworkCredential(ftpusername, ftppassword);
        requestFTP.Method = WebRequestMethods.Ftp.UploadFile;
        FileStream fStream = fileInfo.OpenRead();
        int bufferLength = 2048;
        byte[] buffer = new byte[bufferLength];

        Stream uploadStream = requestFTP.GetRequestStream();
        int contentLength = fStream.Read(buffer, 0, bufferLength);

        while (contentLength != 0)
        {
            uploadStream.Write(buffer, 0, contentLength);
            contentLength = fStream.Read(buffer, 0, bufferLength);
        }
        uploadStream.Close();
        fStream.Close();
        requestFTP = null; 

0 个答案:

没有答案