Skip to content

Query URL metadata example

Andrew Lambert edited this page May 20, 2021 · 8 revisions

Remarks

libcURL can be used to query the remote server for metadata about a resource without actually transferring the resource. A typical example would be using the HTTP HEAD request method to determine the size of the resource, but other protocols have comparable features and other kinds of metadata may be available.

Examples

This example queries the modification time of a file on a FTP server.

  Dim RemoteFile As String = "ftp://ftp.example.com/directory/subdirectory/file.bin"
  Dim curl As New cURLClient
  Call curl.SetOption(libcURL.Opts.FILETIME, True) ' request file time
  If curl.Head(RemoteFile) Then ' Perform a headers-only operation
    ' Get the modification date if it was available.
    Dim modtime As Date = curl.GetInfo(libcURL.Info.FILETIME)
    If modtime <> Nil Then MsgBox("Last modified: " + modtime.SQLDateTime)
  Else
    MsgBox(libcURL.FormatError(curl.LastError))
  End If

This example queries the size of a file on a HTTP server.

  Dim RemoteFile As String = "http://www.example.com/directory/subdirectory/file.bin"
  Dim curl As New cURLClient
  If curl.Head(RemoteFile) Then ' Perform a headers-only operation
    ' Get the length of the download
    Dim size As Integer = curl.GetInfo(libcURL.Info.CONTENT_LENGTH_DOWNLOAD)
    MsgBox("File size: " + Str(size) + " bytes.")
  Else
    MsgBox(libcURL.FormatError(curl.LastError))
  End If

Clone this wiki locally