Filesize using Wininet but not using ftp protocol

Hi.

Question same as in title. Need to find out what is the file size (in bytes) that is placed on web server. Is it possible when working with wininet ??

Thank you in advance
MurdocAsked:
Who is Participating?
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
better yet, you can do it like this with HttpQueryInfo:

var
  hSession: HINTERNET;
  hService: HINTERNET;
  FileSize: Longint;
  dwSize, Reserved: DWORD;
  buf: String;
begin
  hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 );
  if Assigned( hSession ) then
  begin
    hService := InternetOpenUrl(hSession, PChar(sURL), nil, 0, 0, 0);
    if Assigned( hService ) then
    begin
      dwSize := sizeof(FileSize);
      Reserved := 0;
      HttpQueryInfo(hService, HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER,
                    @FileSize, dwSize, Reserved);
      buf := Format('FileSize:%d', [FileSize]);
      Memo1.Lines.Add( buf );
    end;
    InternetCloseHandle( hService );
  end;
  InternetCloseHandle( hSession );
end;
0
 
MurdocAuthor Commented:
..i forgot to tell you that i do not want to use wininet ftp protocol   :)
0
 
Eddie ShipmanAll-around developerCommented:
I think that if you do a HEAD, you can check the content-length...
0
 
MurdocAuthor Commented:
Thanks a lot Eddie.
0
All Courses

From novice to tech pro — start learning today.