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

從帶有進度的 FTP 下載文件 - TotalBytesToReceive 始終

Download file from FTP with Progress - TotalBytesToReceive is always -1?(從帶有進度的 FTP 下載文件 - TotalBytesToReceive 始終為 -1?)
本文介紹了從帶有進度的 FTP 下載文件 - TotalBytesToReceive 始終為 -1?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試從帶有進度條的 FTP 服務器下載文件.

I am trying to download a file from an FTP server with a progress bar.

文件正在下載,ProgressChanged 事件正在調用,但在事件中,參數 TotalBytesToReceive 始終為 -1.TotalBytes 增加,但我無法計算沒有總數的百分比.

The file is downloading, and the ProgressChanged event is calling, except in the event args TotalBytesToReceive is always -1. TotalBytes increases, but I am unable to calculate the percentage without the total.

我想我可以通過其他 ftp 命令找到文件大小,但我想知道為什么這不起作用?

I imagine I could find the file size through other ftp commands, but I wonder why this doesn't work?

我的代碼:

FTPClient request = new FTPClient();
request.Credentials = credentials;
request.DownloadProgressChanged += new DownloadProgressChangedEventHandler(request_DownloadProgressChanged);
//request.DownloadDataCompleted += new DownloadDataCompletedEventHandler(request_DownloadDataCompleted);
request.DownloadDataAsync(new Uri(folder + file));
while (request.IsBusy) ;

....

static void request_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    if (e.TotalBytesToReceive == -1)
    {
        l.reportProgress(-1, FormatBytes(e.BytesReceived) + " out of ?" );
    }
    else
    {
        l.reportProgress(e.ProgressPercentage, "Downloaded " + FormatBytes(e.BytesReceived) + " out of " + FormatBytes(e.TotalBytesToReceive) + " (" + e.ProgressPercentage + "%)");
    }
}

....

class FTPClient : WebClient
{
    protected override WebRequest GetWebRequest(System.Uri address)
    {
        FtpWebRequest req = (FtpWebRequest)base.GetWebRequest(address);
        req.UsePassive = false;
        return req;
    }
}

謝謝.

推薦答案

所以我遇到了同樣的問題.我通過首先檢索文件大小來解決它.

So I had the same issue. I got around it by retrieving the file size first.

        // Get the object used to communicate with the server.
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("URL");
        request.Method = WebRequestMethods.Ftp.GetFileSize;
        request.Credentials = networkCredential;
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();

        Stream responseStream = response.GetResponseStream();
        bytes_total = response.ContentLength; //this is an int member variable stored for later
        Console.WriteLine("Fetch Complete, ContentLength {0}", response.ContentLength);
        response.Close();

        webClient = new MyWebClient();
        webClient.Credentials = networkCredential; ;
        webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(FTPDownloadCompleted);
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(FTPDownloadProgressChanged);
        webClient.DownloadDataAsync(new Uri("URL"));

然后在回調中進行數學運算.

Then do the math in the callback.

private void FTPDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
     progressBar.Value = (int)(((float)e.BytesReceived / (float)bytes_total) * 100.0);
}

這篇關于從帶有進度的 FTP 下載文件 - TotalBytesToReceive 始終為 -1?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 精品视频久久久 | 欧美综合一区 | 成人高潮片免费视频欧美 | av在线免费观看网址 | 中文字幕 国产 | 日本a∨视频 | xxxxx免费视频 | 欧美一区在线视频 | 狠狠干天天干 | 欧美国产日本一区 | 亚洲欧美中文日韩在线 | 日韩精品免费一区二区在线观看 | 欧洲尺码日本国产精品 | 国产乱码一区 | 国产精品性做久久久久久 | 国产精品区二区三区日本 | 久久婷婷麻豆国产91天堂 | 久久合久久 | 日韩亚洲一区二区 | 亚洲成人一级片 | 中文字幕国产一区 | 日韩欧美在线视频 | 免费视频成人国产精品网站 | 成人水多啪啪片 | 日韩精品在线观看一区二区 | 欧美区日韩区 | 成人婷婷| 久久99精品久久久水蜜桃 | 亚洲日韩欧美一区二区在线 | 亚洲精选久久 | 国产精品精品视频一区二区三区 | 亚洲精品一区二区三区中文字幕 | 91精品国产91久久久久久密臀 | 国产中文在线 | 日韩三区 | 天天插天天搞 | www国产成人免费观看视频 | 日本视频一区二区 | 日韩在线电影 | 精品视频一区二区三区在线观看 | 日韩国产一区二区三区 |