ftpwebrequest - C# FtpWebResponse Download throttling -


i tried create ftp download application. , want throttle downloads noob @ wrote can not control speed exactly, mean when write 1024*1024 bytes per second downloads between 400 , 1700 kb's per second need on , told noob please tell answer noobs. thank , sory bad english :d

(note: code includes progressbar , label shows download speed per second)

(note 2: need download big files must use backroundworker , can not use ram keep file before write hdd, need download file hdd directly)

here download code:

ftpwebrequest ftpwbreq = webrequest.create(textbox1.text) ftpwebrequest;         ftpwbreq.method = webrequestmethods.ftp.getfilesize;         ftpwebresponse ftpwebres = ftpwbreq.getresponse() ftpwebresponse;         bytes_total = convert.touint64(ftpwebres.contentlength);         ftpwebres.close();         ftpwebrequest request = (ftpwebrequest)webrequest.create("ftp://"+url);         request.method = webrequestmethods.ftp.downloadfile;         request.credentials = new networkcredential(username, password);         request.usebinary = true;          using (ftpwebresponse response = (ftpwebresponse)request.getresponse())         {             using (stream rs = response.getresponsestream())             {                 using (filestream ws = new filestream(folderbrowserdialog1.selectedpath + "/" + textbox3.text + enson, filemode.create))                 {                     byte[] buffer = new byte[1024];                     int bytesread = rs.read(buffer, 0, buffer.length);                      while (bytesread > 0)                     {                         fileinfo inen = new fileinfo(folderbrowserdialog1.selectedpath + "/" + textbox3.text + enson);                         ws.write(buffer, 0, bytesread);                         bytesread = rs.read(buffer, 0, buffer.length);                         progressbar1.maximum = 2147483646;                         progressbar1.value = convert.toint32((ulong)inen.length * 2147483646 / bytes_total);                         label7.text = inen.length.tostring();                         if (surehesaplama > 50)                         {                             if (checkbox1.checked)                             {                                 if ((inen.length - anlikalinanbyte) / (surehesaplama * 10) >= ((limit / 1024)-100))                                 {                                     random rastgele = new random();                                     int sayi = rastgele.next(-15, 15);                                     label1.text = convert.tostring((limit / 1024) + sayi);                                 }                                 else                                 {                                     label1.text = convert.tostring((inen.length - anlikalinanbyte) / (surehesaplama * 10));                                 }                             }                             else                             {                                 label1.text = convert.tostring((inen.length - anlikalinanbyte) / (surehesaplama * 10));                             }                              surehesaplama = 0;                             anlikalinanbyte = inen.length;                         }                          try                         {                         if (checkbox1.checked)                         {                                 fileinfo toplaminen = new fileinfo(folderbrowserdialog1.selectedpath + "/" + textbox3.text + enson);                                  asdfghjkl = (ulong)toplaminen.length;                                 try                                 {                                 limit =convert.toint32(hizsiniri.text)*1024;                                 }                                 catch (exception)                                 {                                     limit = 50*1024;                                 }                                  if (limit<50*1024)                                 {                                     limit = 50*1024;                                 }                                   if (limtisaniyesayaci!=0)                                 {                                      ulong aradakifark = (ulong)toplaminen.length - suaninen;                                       while (maxinmesigereken < aradakifark)                                     {                                      }                                     sifirmi = true;                                 }                                 else                                 {                                     sifirmi = false;                                 }                         }                              fileinfo yeniinen = new fileinfo(folderbrowserdialog1.selectedpath + "/" + textbox3.text + enson);                             suaninen = (ulong)yeniinen.length;                             if (sifirmi)                             {                                 limtisaniyesayaci = 0;                             }                         }                         catch (exception e)                         {                             messagebox.show(e.message);                         }                     }                 }             }         } 

problems are:

-my max download speed 4mb's per second in code internet speed 13mb's per second. (if use webclient.webclient.downloadfileasync (new uri(myurl),savepath) can 17mb's per second download speed)

-i can not select spesific download speed limit.

-when try cancel downloading application frozing not crushing

question how can fix problems?


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -