How to? Determine size of file via download link

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
 
May 20, 2008
11,380
98
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
11,380
98
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
11,380
98
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
11,380
98
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
11,380
98
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
11,380
98
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
11,380
98
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
 
Similar threads
Thread starter Title Forum Replies Date
Joe Caverly Determine if program started from command prompt Support 2
Jay Sage How to Determine INI File Used by TCMD Support 6
C Determine process svchost is running Support 13
MickeyF how to determine which program will execute a file Support 10
M How to? How to determine if this is the first time that... Support 5
C How to determine if system is 32 or 64 bit? Support 5
M How to? Determine a whether vars beginning with certain characters exist... Support 5
R History window wrong size, can't remember size change Support 12
fpefpe How to? batch file size Support 2
vefatica Documentation Documentation of popup location and size Support 4
S Increasing Font Point Size in Command Tabs Support 2
S How to? What's the maximum size of the thread text ? Support 5
ntak About window size notification Support 6
Joe Caverly Windows Size is 80x0 Support 2
D Need to set Take Command font size when switching to high DPI display Support 0
rps @FILESIZE[....,a] allocated size not matching Dir results Support 8
D Range command dialog with blank maximum size erases everything Support 5
R How to? Change TCMD tab font size in window menu Support 3
D Get tab position and size Support 6
Alpengreis The TCMD Display problems and font size ... Support 2
C VIEW PRINT - Documentation corrected - Font size Support 8
L alternate streams size not counted Support 7
C Screens of different size and hidden console Support 8
mikea How to? @select[] window size, redux. Support 3
Joe Caverly Window Size (Columns x Rows) Support 2
N Popup Window size too small Support 5
Mordachai how to control window size? Support 10
Joe Caverly New Tab In TCMD Changes TCC Window Size Support 1
R WAD /= size ranges not set correctly Support 5
fpefpe How to? Fonts / Size in console window Support 5
C TCC scrollback buffer size Support 11
M How to? Find out the total allocated size of a directory tree... Support 7
C Size of keystack buffer? Support 2
B Downloading Updates - Error: Wrong file size?? Support 3
C CMD window size and post_exec alias ? Support 6
S How to? Command dialogs vs. size/date/etc. exclusion ranges Support 1
T @ping: response code, data size and documentation incorrect Support 2
vefatica File size = -2? Support 8
vefatica FFIND and size ranges Support 1
fpefpe zip command file size Support 1
G Wrong File Size Support 8
davidebbo History popups doesn't remember its position/size Support 4
S DIR - summary of size of subdirectories??? Support 13
S CLIP file size limit Support 1
S Conditionally MOVE/COPY files on the basis of size Support 1
vefatica Updating v10: error wrong file size Support 2
CWBillow TCC Window size Support 5
Fross Win7 x64 Dialog Size Issue Support 3
Roedy CDD command window size Support 6
K popup menu size Support 2

Similar threads