FtpWebRequest获取下载的字节数

时间:2016-11-04 08:14:05

标签: c# asynchronous ftp progress-bar ftpwebrequest

我有这个问题:这是我的代码:

public async Task<string> UploadFile(byte[] fileBytes, string destName)
{      
  FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://xxx.xxx.xxx.xxx" + destName);
  request.Method = WebRequestMethods.Ftp.UploadFile;
  request.Credentials = new NetworkCredential("username", "password");
  request.UseBinary = true;
  request.UsePassive = true;
  request.ContentLength = fileBytes.Length;
  using (Stream s = request.GetRequestStream())
  {
    s.Write(fileBytes, 0, fileBytes.Length);
  }          
  WebResponse ftpResp = await (Task<WebResponse>)request.GetResponseAsync();
  return ftpResp.ToString();
}

并且它已经开始了,但我希望在ProgressBar中使用回调来显示上传的百分比和下载的相对字节数...

我该怎么做?

0 个答案:

没有答案