The problem is still occuring.
Here is my code:
Code:
FILE *pfile = fopen(file, "wb");
char buff[8000];
char writebuff[8000];
sock s;
int first = 0;
int total = 0;
startup();
opensock(&s);
sockconnect(&s, "<my_host>", 80);
write(&s, "GET /<my_file>.zip HTTP/1.1\r\n");
write(&s, "HOST:<my_host>\r\n");
write(&s, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n");
write(&s, "Connection: Close\r\n\r\n"); int i = 0;
while(1) {
total += i;
memset(buff, 0, 8000);
if ((i = read(&s, buff, 8000)) > 0) {
printf("READ: %d\n", i);
memset(writebuff, 0, 8000);
if (!first) {
char secbuff[8000];
substring(buff, secbuff, indexofstr(buff, "\r\n\r\n", 1) + 4, i);
strncpy(writebuff, secbuff, (i - (indexofstr(buff, "\r\n\r\n", 1) + 4)) + 1);
}
else {
strncpy(writebuff, buff,i + 1);
}
if (!first) { fwrite(writebuff, sizeof(char),(i - (indexofstr(buff, "\r\n\r\n", 1) + 4)) + 1, pfile); printf("WROTE: %d out of: %d\n", (i - (indexofstr(buff, "\r\n\r\n", 1) + 4)) + 1, i);}
else { fwrite(writebuff, sizeof(char), i + 1, pfile); }
fflush(pfile);
}
else { break; }
if (!first) { printf("%s", buff); first = 1; }
}
fclose(pfile);
closesocket((SOCKET) s);
printf("\n\n\nTotal bytes read: %d\n", total);