上下文如下:我接收带有俄语文本的 xml 文件,我的 FileSystemWacher on Create 事件将它们传输到内部 ftp 服务器,如下所示:
公共静态 FtpWebResponse UploadFile(字符串 localFile,字符串 ftpFile,NetworkCredential 凭据){
//Thread.Sleep(2000);
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpFile);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UseBinary = true;
request.Proxy = null;
request.Credentials = credentials;
using (FileStream sourceStream = new FileStream(localFile,FileMode.Open))
using (Stream requestStream = request.GetRequestStream())
{
CopyStream(sourceStream, requestStream);
}
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
return response;
}
private static void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[32768]; while (true) { int read = input.Read(buffer, 0, buffer.Length); 如果(读取 <= 0)返回;output.Write(buffer, 0, read); } }
传输后,在 ftp 端,文件如下所示:
<OTPR consignment_number="33504655" weight_of_load="57160" forwarding_railway="22" forwarding_station="330206" consignor="3590" name_of_consignor="пїЅпїЅпїЅ "пїЅпїЅпїЅпїЅпїЅпїЅIпїЅ-пїЅпїЅпїЅпїЅIпїЅпїЅпїЅпїЅпїЅ". 18011. пїЅ. пїЅпїЅпїЅпїЅпїЅпїЅпїЅ. пїЅпїЅпїЅ.пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅ.1 пїЅпїЅIпїЅ 225. 0472719922." destination_railway="53" destination_station="517508" consignee="9999" name_of_consignee="пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ." packing="2" nhm="12019000" name_of_load="пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ" dt="24012013" />
不像原来的:
<OTPR consignment_number="33504671" weight_of_load="58740" forwarding_railway="22" forwarding_station="330206" consignor="3590" name_of_consignor="ТОВ "КОМПАНIЯ-АГРОIНВЕСТ". 18011. М. ЧЕРКАСИ. ВУЛ.ДОБРОВОЛЬСЬКОГО, БУД.1 ОФIС 225. 0472719922." destination_railway="53" destination_station="517508" consignee="9999" name_of_consignee="БУНГЕ РОМАНИЯ СРЛ." packing="2" nhm="12019000" name_of_load="БОБЫ СОЕВЫЕ" dt="24012013" />