// JP opened flex table

Click to See Complete Forum and Search --> : How to get file size of CInternetFile object?


wangdave
May 17th, 2002, 04:18 AM
Hi,
We know that CInternetFile is derived from CStdioFile and CFile.
I have a CInternetFile object, and I used member function of this class'
parent,
GetLength() to get size of internet file.
But I got an error result.

This error only occurs while the internet file is big.(about 2M Bytes).

Why? Then,what can I do to get file size of CInternetFile object?

Thanks.

dental_care
May 17th, 2002, 04:29 AM
Microsoft's implementation of CInternetFile indeed gives the illusion of http files working as regular files. Well, that's not the case. HTTP is a very simple protocol lacking many administrative goodies found in for instance FTP.

The first thing getting sent when you request a file from a HTTP server is a block of headers which contains all information about the file getting sent. One of these headers is called "Content-Length" and gives the number of bytes being sent in the response. You have to read this header or perhaps find some method in the API which reads it.

As I said, the protocol is simple. Each header is terminated by a crlf pair, and when the headers end (the content begins) you'll find two crlf pairs (virtually an empty line).


Regards.
/Robert

wangdave
May 20th, 2002, 03:23 AM
Yes,good! CHttpFile::QueryInfo() works fine for CHttpFile, which is for url: "http://...".
But how to get CInternetFile size for url: "ftp://...."?
Thank you!
wangdave

Originally posted by dental_care
Microsoft's implementation of CInternetFile indeed gives the illusion of http files working as regular files. Well, that's not the case. HTTP is a very simple protocol lacking many administrative goodies found in for instance FTP.

The first thing getting sent when you request a file from a HTTP server is a block of headers which contains all information about the file getting sent. One of these headers is called "Content-Length" and gives the number of bytes being sent in the response. You have to read this header or perhaps find some method in the API which reads it.

As I said, the protocol is simple. Each header is terminated by a crlf pair, and when the headers end (the content begins) you'll find two crlf pairs (virtually an empty line).


Regards.
/Robert

Mansukh Patidar
May 20th, 2002, 03:30 AM
hi,
Use this function to find the FTP file size


DWORD FtpGetFileSize(
HINTERNET hFile,
LPDWORD lpdwFileSizeHigh
);

wangdave
May 20th, 2002, 04:53 AM
But I got a compiling error: 'FtpGetFileSize' : undeclared identifier.
The code is :
DWORD dwLenLow = FtpGetFileSize(
HINTERNET(*file),&dwLenHigh);
In addition, MSDN said:
"
Be aware that FtpGetFileSize is not always successful in getting the file size because of the variety of ways that FTP servers return directory listing information. "

Then, a new question occurs, how to determine if this API is successful?


Originally posted by Mansukh Patidar
hi,
Use this function to find the FTP file size


DWORD FtpGetFileSize(
HINTERNET hFile,
LPDWORD lpdwFileSizeHigh
);

Mansukh Patidar
May 20th, 2002, 05:20 AM
#include <Wininet.h>

wangdave
May 20th, 2002, 05:32 AM
Certainly,I had added that include file. Perhaps this copy is not up-to-date. My VC is VC6.0.
I will try to download a new copy of SDK.

Originally posted by Mansukh Patidar
#include <Wininet.h>

EvoPeteMTL
June 30th, 2006, 11:31 AM
I have exactly the same problem with the FtpGetFileSize and I see others on other forums with the same. I guess it depends on the functionality of the ftp server. You did add the wininet.lib too right?

Ejaz
June 30th, 2006, 02:05 PM
I have exactly the same problem with the FtpGetFileSize and I see others on other forums with the same. I guess it depends on the functionality of the ftp server. You did add the wininet.lib too right?

You are asking the question to the guy who last participated in this thread about 4 years back :) And the error has nothing to do with .lib as its a compile time error, not linking error.

#include <Wininet.h>

should solve the problem as mentioned earlier.

Marc G
July 1st, 2006, 03:30 AM
[ moved thread ]

//JP added flex table