使用下面的代碼我試圖將加密文件上傳到FTP服務器。 從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();
任何線索可能是什麼問題?
不要往返ASCII。這會破壞所有字節> 127。 – CodesInChaos
取消註釋'byte [] fileContents = File.ReadAllBytes(tempfilepath);' –