How to get the lenght of this.. ? please help

how do i get the lenght of the remote http file, before downloading it ?

define HTTPBUFLEN 512 // Size of HTTP Buffer...
char httpbuff[HTTPBUFLEN];
TCHAR szCause[255];
CString Cause;
CString contentlength;
Cause.Format("YES");
DWORD length;

CInternetSession mysession;
CStdioFile *remotefile = mysession.OpenURL(url,1,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD);
CFile myfile("C:\\test.txt", CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);

int numbytes;


total=0;
do
{

ProcessMessages();
m_status.Format("%i",total);
UpdateData(FALSE);
numbytes = remotefile->Read(httpbuff, HTTPBUFLEN);
total+=numbytes;
myfile.Write(httpbuff, numbytes);


}while (numbytes);


hope you can help me, thanks
[884 byte] By [KixXaSs] at [2007-11-17 2:26:50]
«« socket
»» buttons
# 1 Re: How to get the lenght of this.. ? please help
Did you try calling GetLength()?

Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
--===--
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
--===--
Daniel
DanielK at 2007-11-10 6:58:40 >
# 2 Re: How to get the lenght of this.. ? please help
GetLength() always returns a number around 800, sometimes 801 , sometimes 799, but thats not the real size of the remote file ! it shows 800 or something, no matter if the file is 3 MB or 1 kb
KixXaSs at 2007-11-10 6:59:41 >
# 3 Re: How to get the lenght of this.. ? please help
"how do i get the lenght of the remote http file, before downloading it"?
I don't know why, but sometime it's just not possible
So, you have to download in loop until Read() function returns a value more than 0.

Good luck
Please rate if you think this response was useful for you
Serguei Batchila at 2007-11-10 7:00:40 >
# 4 Re: How to get the lenght of this.. ? please help
Comeon, there MUST be a way to get the length of the remote file before downloading, or how do download managers like gozilla , getright, etc do it ?
KixXaSs at 2007-11-10 7:01:36 >
# 5 Re: How to get the lenght of this.. ? please help
Comeon, there MUST be a way to get the length of the remote file before downloading, or how do download managers like gozilla , getright, etc do it ?"??
KixXaSs at 2007-11-10 7:02:35 >
# 6 Re: How to get the lenght of this.. ? please help
Sometimes even getright can't get the size.

Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
--===--
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
--===--
Daniel
DanielK at 2007-11-10 7:03:46 >
# 7 Re: How to get the lenght of this.. ? please help
I don't say there are no way. I just said this way doesn't always work. Have you ever seen Internet explorer 'downloading' dialog with the text 'file length unknown?'. That's because it wasn't possible to get a file length
I don't see any problems with Gozilla etc. The do it as I described - try to read until Read function returns 0.
Sometime when you download HTML page, you download not an HTML file from server's Hard Drive, but a server generates HTML for you in run time. For example, all these Internet stores. How do you think it's possible to get the file lengh in this case if there are no file at all?

Good luck
Please rate if you think this response was useful for you
Serguei Batchila at 2007-11-10 7:04:39 >