Before downloading a remote file (for example, from an FTP server), a user often wants to know in advance information about the file size, its md5 checksum, last modified date (exactly there on the server, not on the local disk), etc.
The following handler will help them get all the information as usual AppleScript record:
on remoteFileInfo(theURL)
set requestResponse to do shell script "curl -s --head " & theURL
set remoteFileExists to word 3 of requestResponse
if remoteFileExists = "200" then return ({«class usrf»:(do shell script "curl -s --head " & theURL & " | egrep -o '\\w[^:]+|:.+' | awk '{gsub(\" +$|: \",\"\"); print} ' ")'s paragraphs 2 thru -1})'s contents as any
return "File Not Founded"
end remoteFileInfo
set theURL to "https://cdn-dist.emclient.com/dist/v9.1.2109_Mac/setup.pkg"
set remoteFileInfoRecord to remoteFileInfo(theURL)
Here is examples of gotten record keys values:
set fileSize to |content-length| of remoteFileInfoRecord
--> 112531050 (bytes)
set lastModifiedDate to |last-modified| of remoteFileInfoRecord
--> Thu, 11 Aug 2022 12:35:46 GMT