我正在尝试从带有进度条的FTP服务器下载文件.
文件正在下载,并且ProgressChanged事件正在调用,除非事件args TotalBytesToReceive始终为-1.TotalBytes增加,但我无法计算没有总数的百分比.
我想我可以通过其他ftp命令找到文件大小,但我想知道为什么这不起作用?
我的代码:
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) ;
Run Code Online (Sandbox Code Playgroud)
....
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 + "%)");
}
}
Run Code Online (Sandbox Code Playgroud)
....
class FTPClient : WebClient
{
protected …Run Code Online (Sandbox Code Playgroud)