我有代码,我将 xml 文件发送到 ftp 服务器,但 ftp 服务器上的文件大小小于原始文件。我正在尝试启用二进制传输,但结果仍然相同。
FileInfo f = new FileInfo("C:\\Users\\L\\Desktop\\data.xml");
long original_vel = f.Length;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://***");
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.GetFileSize;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("*****", "*****");
StreamReader sourceStream = new StreamReader(@"C:\\Users\\L\\Desktop\\data.xml");
byte[] fileContents = Encoding.Unicode.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
long ftp_vel = request.ContentLength;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
if (original_vel == ftp_vel)
{
response.Close();
}
else
{
Odesilani();
}
原始文件的大小是294 672,但是ftp上的文件有294 670。
The xml file on ftp is valid....But when i compare files in total comander, the original file have: FF FE 3C 00 3F 00.....and the file on ftp have 3C 00 3F 00...
但是文件的内容还可以......:/你知道吗?