is there a way using Applescript or a shell script to get the size of a remote file?
Is the file on a mounted volume or just sitting on a server?
On a remote server
I won’t claim to know what I’m talking about but it looks like curl might be able to get the size of a file. Use ‘man curl’ in Terminal to explore the many features of curl. The part that I think might be helpful is:
-I/--head
(HTTP/FTP) Fetch the HTTP-header only! HTTP-servers
feature the command HEAD which this uses to get
nothing but the header of a document. When used on a
FTP file, curl displays the file size only.
Wonderfull, I missed it when I red the manual of curl, thanks Rob
If you come up with a way to wrap a curl command in AppleScript to get a remote file’s size, I’d appreciate a sample of the code if you’d care to share it.
This one is only experimental :
on getFileSize(theURL)
try
set header to do shell script "curl -l --head " & theURL
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Content-Length: "}
set fileSize to paragraph 1 of text item 2 of header
set AppleScript's text item delimiters to oldTID
return fileSize / 1024
on error
return 0
end try
end getFileSize
Nice experiment! It works great here! Thanks!
I know this thread is old, but I have been working on this very thing with know luck. I tried Jean Baptiste and I am getting a Access denied: 530. I am sure it is because I am not feeding the ftp site my username and password, but when I add
I am still getting a permissions error. So far, my script looks like this:
set theURL to "ftp://206.225.11.6/REVIEW/"
try
set header to do shell script "curl -l --head " & theURL
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Content-Length: "}
set fileSize to paragraph 1 of text item 2 of header
set AppleScript's text item delimiters to oldTID
return fileSize / 1024
on error
return 0
end try
Thank you so much in advance.