to make a upload of a file via ftp I use the Inet classes of MFC.
Unfortunaly I found out no way to get the length of the file bevor
the tranfer. The user should displayed how long it takes to download
the file.
CInternetFile* ifile = myftpc->OpenFile(s1, access,ttype);
int l= ifile->GetLength();
I tried this but it don't work. In 'l' you will find the length of
a local file with the same name or an undefined value. Seems to
be a bug (MFC 4.21 VC 5).
Has anybody a better idea or a workaround ?
Hans
Sorry if this repons arrive too late, but...
ifile->GetLength() does'nt work because :
1.1 - MFC implementation
DWORD CInternetFile::GetLength() const
{
DWORD dwRet = 0;
if (!InternetQueryDataAvailable(m_hFile, &dwRet, 0, 0))
dwRet = 0;
return dwRet;
}
1.2 - InternetQueryDataAvailable documentation :
This function returns the number of bytes of data that are available to be
read immediately by a subsequent call to InternetReadFile. If there is
currently no data available and the end of the file has not been reached,
the request waits until data becomes available. The amount of data remaining
will not be recalculated until all of the available data indicated by the
call to InternetQueryDataAvailable is read.
2 The solution :
You must use QueryInfo for get the length of the file if kwown (in the http
header) :
fSuccess = ifile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH |
HTTP_QUERY_FLAG_NUMBER, &count, &sizeVar);
If fSucces is false (the server don't know the information) you must stop
reading when the count of bytes readed is 0.