Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Determine size of file via download link

Aug
2,073
84
I am able to determine the size of a file before I download it using curl

Examples;
upload_2016-9-4_13-55-2.png


and

upload_2016-9-4_13-56-1.png


Using TCC, is there a method of getting the size of a file (Content-Length) via the download link, as I am presently doing with curl?

Thanks from Joe
 
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
 
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.
 
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.
 
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
 
Vince, thanks for the info on the %@ifilesize function from 4UTILS.

I downloaded the plugin, but it does not seem to work for me;

upload_2016-9-5_5-15-15.png


Joe
 
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.
 
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.

I did some searching, and found an older copy of 4UTILS, and it works;

upload_2016-9-5_12-9-39.png


Joe
 
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.
 
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
 
Vince, thanks for the ftptime function. Unfortunately, it does not work on http.

curl, however, does provide the files last modified date and time;

upload_2016-9-5_18-46-29.png


Thus;

upload_2016-9-5_18-47-44.png


Your @ifiletime returns the same results;

upload_2016-9-5_18-49-43.png


Joe
 
If 4UTILS is working for you, @IFILETIME will work for HTTP (and not for FTP).
 
Back
Top
[FOX] Ultimate Translator
Translate