Checking size of file on web server...

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I trying to write a script to compare filesizes of local and remote (on a web server) files...

I can get the local filesize by using:


Code:
Dim localFileSize As Long
localFileSize = FileLen(ThisWorkbook.Path  & Filename)

MsgBox "local - " & localFileSize

I can check if my 'remote' file exists by using:

Code:
Dim doesFileExist As Boolean
doesFileExist = checkFile("http://www.mywebserver.com/files/" & Filename)
MsgBox "Remote file exists - " & doesFileExist

which returns a true or false. But for the life of me I can't return the filesize of the file on the remote server....

If you can point me in the right direction, I'd be extremely happy :)

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Assume you tried FileLen and it didn't work?

How about using FileSystemObject?

Worst case, you could open the file and use the LOF function.
 
Upvote 0
Yeah, FileLen only seems to work locally...

I've never used FileSystemObject - I've googled it, but can't find anything which will simply do the above.

I'm just trying to identify if the file is smaller online so that a backup can be determined - there are lots of files to compare, so downloading and LOF function on each will be a nightmare...

Is there a simple way to use FileSystemObject?

Thanks shg
 
Upvote 0
I don't know if FSO works with a web server, and can't conveniently test it.

Comparing file size is not too rigorous as a means of determining if one file is the same as another.
 
Upvote 0
Can anyone help me with returning the file size of a file on an online server?

Code:
Dim doesFileExist As Boolean
doesFileExist = checkFile("http://www.mywebserver.com/files/" & Filename)
This code simply returns whether it exists or not. Surely there must be an equally simple way to return the file size?

This is driving me crazy :S

Thanks
 
Upvote 0
You need to do an HTTP request, using the HEAD type and check the content-length property. Since you already have code to check if the file exists, I'll assume you know how to do that.
 
Upvote 0
Thanks Kyle, I kinda guessed that I was close, but unfortunately I don't know to do an HTTP request, using the HEAD type and check the content-length property...

Can you help me with this bit?
 
Upvote 0
I'm using:

Code:
Dim doesFileExist As Boolean
doesFileExist = checkFile("http://www.mywebserver.com/files/" & Filename)
MsgBox "Remote file exists - " & doesFileExist

This returns a True/False
 
Upvote 0
checkFile isn't VBA. It's something bespoke that you (or someone on your behalf) has written. Please post the actual code of checkFile
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top