Asp.net DownloadFileAsync与webclient问题
我正在尝试使用Webclient DownloadFileAsync方法从FTP下载文件。我使用了下面的代码Asp.net DownloadFileAsync与webclient问题,asp.net,ftp,Asp.net,Ftp,我正在尝试使用Webclient DownloadFileAsync方法从FTP下载文件。我使用了下面的代码 private bool DownloadFileFromFtp() { try { MyWebClient client = new MyWebClient(); Uri ftpurl = new Uri("ftp://MyFtpserver/Filename.pdf"); client.Credentials =
private bool DownloadFileFromFtp()
{
try
{
MyWebClient client = new MyWebClient();
Uri ftpurl = new Uri("ftp://MyFtpserver/Filename.pdf");
client.Credentials = new NetworkCredential("Userid", "mypassword");
client.DownloadProgressChanged += Client_DownloadProgressChanged;
client.DownloadDataCompleted += Client_DownloadDataCompleted;
client.DownloadFileAsync(ftpurl, @"D:\RTP\Filename.pdf");
return true;
}
catch (Exception ex)
{
return false;
}
}
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
lbldatareceived.Text = bytesIn + "/" + totalBytes;
lblPercentage.Text = percentage+"%";
FileProgress.Attributes.CssStyle.Add("width", Convert.ToString(percentage) + '%');
FileProgress.Attributes.Add("aria-valuenow", Convert.ToString(percentage));
}
private void Client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
throw new NotImplementedException();
}
当我运行此代码文件时,下载开始,浏览器开始加载。如何在不加载浏览器的情况下下载文件 请不要将C#代码标记为可以在浏览器中运行的Javascript代码。HTTP是请求/响应。当浏览器显示空进度条时,响应结束。作为服务器,您无法(使用普通HTTP)发送进一步的更新,例如应用新的CSS或属性。