久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='Qi4Qz'></tfoot>

  1. <i id='Qi4Qz'><tr id='Qi4Qz'><dt id='Qi4Qz'><q id='Qi4Qz'><span id='Qi4Qz'><b id='Qi4Qz'><form id='Qi4Qz'><ins id='Qi4Qz'></ins><ul id='Qi4Qz'></ul><sub id='Qi4Qz'></sub></form><legend id='Qi4Qz'></legend><bdo id='Qi4Qz'><pre id='Qi4Qz'><center id='Qi4Qz'></center></pre></bdo></b><th id='Qi4Qz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Qi4Qz'><tfoot id='Qi4Qz'></tfoot><dl id='Qi4Qz'><fieldset id='Qi4Qz'></fieldset></dl></div>
    <legend id='Qi4Qz'><style id='Qi4Qz'><dir id='Qi4Qz'><q id='Qi4Qz'></q></dir></style></legend>
      <bdo id='Qi4Qz'></bdo><ul id='Qi4Qz'></ul>

  2. <small id='Qi4Qz'></small><noframes id='Qi4Qz'>

    1. FtpWebRequest 下載文件大小不正確

      FtpWebRequest Download File Incorrect Size(FtpWebRequest 下載文件大小不正確)

      <tfoot id='zasjD'></tfoot>
        <tbody id='zasjD'></tbody>
      <i id='zasjD'><tr id='zasjD'><dt id='zasjD'><q id='zasjD'><span id='zasjD'><b id='zasjD'><form id='zasjD'><ins id='zasjD'></ins><ul id='zasjD'></ul><sub id='zasjD'></sub></form><legend id='zasjD'></legend><bdo id='zasjD'><pre id='zasjD'><center id='zasjD'></center></pre></bdo></b><th id='zasjD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zasjD'><tfoot id='zasjD'></tfoot><dl id='zasjD'><fieldset id='zasjD'></fieldset></dl></div>

          <small id='zasjD'></small><noframes id='zasjD'>

            • <legend id='zasjD'><style id='zasjD'><dir id='zasjD'><q id='zasjD'></q></dir></style></legend>
                <bdo id='zasjD'></bdo><ul id='zasjD'></ul>
                本文介紹了FtpWebRequest 下載文件大小不正確的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我正在使用以下代碼從遠程 ftp 服務器下載文件:

                I’m using the following code to download a file from a remote ftp server:

                        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);
                
                        request.KeepAlive = true;
                        request.UsePassive = true;
                        request.UseBinary = true;
                
                        request.Method = WebRequestMethods.Ftp.DownloadFile;
                        request.Credentials = new NetworkCredential(userName, password);                
                
                        using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                        using (Stream responseStream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(responseStream))
                        using (StreamWriter destination = new StreamWriter(destinationFile))
                        {
                            destination.Write(reader.ReadToEnd());
                            destination.Flush();
                        }
                

                我正在下載的文件是一個 dll,我的問題是它被這個過程以某種方式改變了.我知道這是因為文件大小在增加.我懷疑這部分代碼有問題:

                The file that I’m downloading is a dll and my problem is that it is being altered by this process in some way. I know this because the file size is increasing. I have a suspicion that this section of code is at fault:

                        destination.Write(reader.ReadToEnd());
                        destination.Flush();
                

                任何人都可以就可能出現的問題提供任何想法嗎?

                Can anyone offer any ideas as to what may be wrong?

                推薦答案

                StreamReaderStreamWriter 處理字符數據,因此您正在將流從字節解碼為字符并然后再次將其編碼回字節.dll 文件包含二進制數據,因此這種往返轉換會引入錯誤.您想直接從 responseStream 對象讀取字節并寫入未包裝在 StreamWriter 中的 FileStream.

                StreamReader and StreamWriter work with character data, so you are decoding the stream from bytes to characters and then encoding it back to bytes again. A dll file contains binary data, so this round-trip conversion will introduce errors. You want to read bytes directly from the responseStream object and write to a FileStream that isn't wrapped in a StreamWriter.

                如果您使用的是 .NET 4.0,則可以使用 Stream.CopyTo,否則您將不得不手動復制流.這個StackOverflow問題有一個很好的復制流的方法:

                If you are using .NET 4.0 you can use Stream.CopyTo, but otherwise you will have to copy the stream manually. This StackOverflow question has a good method for copying streams:

                public static void CopyStream(Stream input, Stream output)
                {
                    byte[] buffer = new byte[32768];
                    while (true)
                    {
                        int read = input.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                            return;
                        output.Write(buffer, 0, read);
                    }
                }
                

                因此,您的代碼將如下所示:

                So, your code will look like this:

                using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                using (Stream responseStream = response.GetResponseStream())
                using (FileStream destination = File.Create(destinationFile))
                {
                    CopyStream(responseStream, destination);
                }
                

                這篇關于FtpWebRequest 下載文件大小不正確的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                onClick event for Image in Unity(Unity中圖像的onClick事件)
                Running Total C#(運行總 C#)
                Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                <tfoot id='hzv8R'></tfoot>
                  <bdo id='hzv8R'></bdo><ul id='hzv8R'></ul>

                      1. <legend id='hzv8R'><style id='hzv8R'><dir id='hzv8R'><q id='hzv8R'></q></dir></style></legend>
                          <i id='hzv8R'><tr id='hzv8R'><dt id='hzv8R'><q id='hzv8R'><span id='hzv8R'><b id='hzv8R'><form id='hzv8R'><ins id='hzv8R'></ins><ul id='hzv8R'></ul><sub id='hzv8R'></sub></form><legend id='hzv8R'></legend><bdo id='hzv8R'><pre id='hzv8R'><center id='hzv8R'></center></pre></bdo></b><th id='hzv8R'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hzv8R'><tfoot id='hzv8R'></tfoot><dl id='hzv8R'><fieldset id='hzv8R'></fieldset></dl></div>
                            <tbody id='hzv8R'></tbody>

                        • <small id='hzv8R'></small><noframes id='hzv8R'>

                          主站蜘蛛池模板: 欧美激情一区二区三区 | 久久久久久成人 | 亚洲免费精品 | 日韩欧美国产不卡 | 欧美午夜一区 | 性福视频在线观看 | 黄色小视频大全 | 美女日批免费视频 | 97国产精品视频人人做人人爱 | 国产91丝袜在线播放 | 色性av| 国产色婷婷 | 福利视频三区 | 97超碰成人 | 国产精品成人一区二区三区吃奶 | 中文字幕乱码一区二区三区 | 国产一区二区久久 | 美女在线国产 | 日韩精品久久 | 免费国产一区二区视频 | 国产资源在线播放 | 久久精品 | 欧美久久国产精品 | 91在线视频免费观看 | 免费在线观看一级毛片 | 亚洲国产欧美日韩 | 日韩一二三区 | 一区二区久久 | 一区二区三区四区av | 国产精品亚洲一区二区三区在线 | 国产精品欧美一区喷水 | 日韩一区二区三区在线视频 | 国产不卡视频在线 | 国产xxxx在线 | 盗摄精品av一区二区三区 | 亚洲成人黄色 | 免费看国产一级特黄aaaa大片 | a黄视频| 91久久久久久久久久久 | 成年精品| 日韩一级黄色毛片 |