How to? Determine size of file via download link

May 20, 2008
9,204
60
Syracuse, NY, USA
4UTILS has @IFILESIZE but it doesn't work via FTP.
Code:
v:\> echo %@ifilesize[jpsoft.com/downloads/v16/tcmd.exe]
21593248
How about good old fashioned brute force?
Code:
v:\> echo %@strip[^,,%@word[" ",2,%@execstr[dir /m /k ftp://lucky.syr.edu/4plugins/4autotray.zip]]]
106231
 
May 20, 2008
9,204
60
Syracuse, NY, USA
HTTP(S) doesn't provide a means to get the file size. The only way to do that is with FTP.
I don't know about HTTP itself, but you can do it with WININET functions.
InternetOpen()
InternetConnect() with nServerPort ==INTERNET_DEFAULT_HTTP_PORT
HttpOpenRequest() with the verb L"HEAD"
HttpSendRequest()
HttpQueryInfo() with dwInfoLevel == HTTP_QUERY_CONTENT_LENGTH

You can also use HTTP_QUERY_LAST_MODIFIED.

I haven't tried it, but you can InternetConnect() with INTERNET_DEFAULT_HTTPS_PORT also.
 
May 20, 2008
9,204
60
Syracuse, NY, USA
Here's a cute way with two examples of its use.
Code:
v:\> function ftpsize `%@word[1,%@execstr[1,iftp /v ftp://%1 > NUL & iftp /s size %2 & iftp /c]]`

v:\> echo %@ftpsize[lucky.syr.edu/4plugins,4autotray.zip]
106231

v:\> echo %@ftpsize[lucky.syr.edu/,4plugins/4autotray.zip]
106231
I don't know if a server's response to the SIZE command has a standard format. If not, the above may not work everywhere.
 
May 20, 2008
9,204
60
Syracuse, NY, USA
HTTP(S) doesn't provide a means to get the file size. The only way to do that is with FTP.
According to IPWorks, their v9 HTTP component supports the HEAD method:

Head Fetches the document headers using the HTTP HEAD method

This might allow TCC to get the size and date of a resource without getting the resource itself.
 
HTTP(S) doesn't provide a means to get the file size. The only way to do that is with FTP.
Not sure how curl does it, but curl does indeed allow me to get the file size via an HTTP link. See the example in my previous post.

Source code for curl is available here.

Visual C++ build instructions here.

This is the function I am presently using,
Code:
urlsize=%@word[1,%@execstr[curl --head --insecure --silent %1 | find "Content-Length"]]
Joe
 
May 20, 2008
9,204
60
Syracuse, NY, USA
Hmmm! I remember making changes which broke the plugins on Windows XP. Here, the one you have works OK with TCCv17 on Windows 7. I don't remember how if fared on Vista. Perhaps Rex will know what's going on. I don't know if I'll be able to fix it.
 
May 20, 2008
9,204
60
Syracuse, NY, USA
Good! I might have found the problem (PSAPI functions moved between Vista and Win7) but I'm not sure how to fix it and I can't test. I hope you're happy for now.
 
May 20, 2008
9,204
60
Syracuse, NY, USA
Here's another similar one for a file's last write time. It's UTC and a datetime but it's better than nothing.
Code:
v:\> function ftptime `%@word[1,%@execstr[1,iftp /v ftp://%1 > NUL & iftp /s mdtm %2 & iftp /c]]`

v:\> echo %@ftptime[lucky.syr.edu/,4plugins/4autotray.zip]
20141202055606.452