久久久久久久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 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 国产精品一区久久久 | 国产精品综合网 | 国产一区二区视频在线 | 国产精品99久久久久久宅男 | 亚洲在线一区二区 | 国外成人在线视频网站 | 自拍 亚洲 欧美 老师 丝袜 | 男人的天堂久久 | 日韩视频一级 | 四虎网站在线观看 | 91免费电影 | h视频在线观看免费 | av在线免费观看网站 | 国产精品美女久久久久 | 欧美激情在线精品一区二区三区 | 在线欧美亚洲 | 日韩视频精品 | 91久久久久久 | 国产自产c区 | 亚洲不卡视频 | 一区二区三区在线看 | 亚洲精品一区中文字幕乱码 | 色婷婷综合久久久中字幕精品久久 | 中文在线a在线 | 亚洲精品乱码久久久久久久久 | 亚洲 欧美 另类 综合 偷拍 | 日韩av看片 | www.久久99 | 仙人掌旅馆在线观看 | 国产视频一区二区 | 亚洲精品在线免费观看视频 | 日韩不卡在线 | 国产精品久久久久久久久图文区 | 欧美高清一级片 | 日韩精品国产精品 | 成人亚洲 | 天天拍天天射 | 欧美精品一区二区在线观看 | 无码国模国产在线观看 | 成人欧美一区二区三区在线观看 | av资源在线看 |