使用下面的代码,我正在尝试将加密文件上传到 FTP 服务器。从 ftp 服务器下载文件时,它们都已损坏。
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(
user,
pass);
StreamReader sourceStream = new StreamReader(tempfilepath);
byte[] fileContents = ASCIIEncoding.ASCII.GetBytes(sourceStream.ReadToEnd()); // uploads corrupted files
//byte[] fileContents = File.ReadAllBytes(tempfilepath);
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
// Shows confirm message
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
任何线索可能是什么问题?