Can anyone tell me download multi connection mechanism of IDM?How it downloads to temporary files and join them.
how to download a file from internet[
^] I using this code to create a program to download one file with 8 connection. I create one connection to download some MB (I divide MB for connection by using webRequest.AddRange(start,end)) and save it with 01.file, 02.file, 03.file. After download successfull but when I Join files, I can't watch video file. Please help me :(
Here is my code:
try
{
HttpWebRequest webRequest;
HttpWebResponse webResponse;
IWebProxy proxy = null;
webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.AddRange((int)start, (int)end);
webRequest.Timeout = 240 * 1000;
webRequest.Proxy = proxy;
webResponse = (HttpWebResponse)webRequest.GetResponse();
fs = new FileStream(
fileName, FileMode.Append, FileAccess.Write);
long fileLength = webResponse.ContentLength;
Stream strm = webResponse.GetResponseStream();
int SeekPosition = (int)start;
Console.WriteLine(name);
strm.ReadTimeout = 60 * 1000;
int arrSize = 18 * 1024 * 1024;
byte[] barr = new byte[arrSize];
long bytesCounter = 0;
while (true)
{
int actualBytes = 0;
try
{
actualBytes = strm.Read(barr, 0, arrSize);
}
catch
{
}
if (actualBytes <= 0)
{
if (fileLength == actualBytes)
break;
else
{
if (tryCounter == 0)
{
tryCounter++;
dStart = DateTime.Now;
continue;
}
if (dStart.AddMinutes(1) >= DateTime.Now)
break;
}
}
fs.Write(barr, 0, actualBytes);
bytesCounter += actualBytes;
Transfered = bytesCounter;
}
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}. Message: {1}", name, ex.Message);
}
finally
{
fs.Flush();
fs.Close();
}