A script to clock an internet download...can it be done?

Hey Guys

I’m looking to write a script that will go to a URL to launch a direct http download, then write the duration of the download, or time the download started and finished, to a text file or preferrably Tex-Edit Plus.

Any ideas?

I’m also looking to script an upload timing in the same way…:slight_smile:

Martin

Hi Martin,

here a quite simple example of the download script to play with:

property httpURL : "http://myDomain.com/myMovie.mov"

set {TID, text item delimiters} to {text item delimiters, "/"}
set fName to last text item of httpURL
set text item delimiters to TID
set destpath to ((path to desktop as Unicode text) & fName)
set logfile to ((path to desktop as Unicode text) & "logfile.txt")

write_to_disk from (((current date) as string) & ": starting download of " & fName & return) into logfile
do shell script "curl -o " & quoted form of POSIX path of destpath & " " & httpURL
write_to_disk from (((current date) as string) & ": download of " & fName & " completed" & return) into logfile

on write_to_disk from theData into targetFile
	set ff to open for access file targetFile with write permission
	write theData to ff starting at eof
	close access ff
end write_to_disk

Hi Stefan…

Awesome script, that was exactly what I was looking for.

What would be the best way for me to engineer exactly the same txt output method but for uploading a file to a webspace? I was keen to send a file up to test my upload speeds are as advertised?

Thanks so much though mate for your help so far.

Martin

Hi Martin,

only to test download/upload speed I would prefer a tool like NetMonitor or Menu Meters,
which displays the current speed in the menu bar

a sample FTP upload routine is this

--the server information
property ftpserver : "[url=ftp://ftp.myserver.com]ftp.myserver.com[/url]" --ftp server 
property ftppath : "/pub/" --the directory on the server (for the root directory, leave this empty)
property server_username : "myusername" --server_username (if you want to get asked for it everytime, leave this empty)
property server_password : "¢¢¢¢¢¢" --server_password (if you want to get asked for it everytime, leave this empty)

set servername to ftpserver & ftppath
set itemPath to quoted form of POSIX path of (choose file)
try --where the file is
	do shell script "curl " & servername & " -u " & server_username & ":" & server_password & " -T " & itemPath
on error e
	display dialog e
end try

If the downloaded material is small, an alternative timer (using Stephan’s first script) could use the osax GetMilliSec


property httpURL : "http://files.macscripter.net/ScriptBuilders/InDesign/export%20all%20pages%20as%20jpeg%201.1.scpt.zip"

set {TID, text item delimiters} to {text item delimiters, "/"}
set fName to last text item of httpURL
set text item delimiters to TID
set destpath to ((path to desktop as Unicode text) & fName)
set logfile to ((path to desktop as Unicode text) & "logfile.txt")

set t1 to (GetMilliSec)
write_to_disk from ("Download of " & fName & return) into logfile
write_to_disk from (("Starting download at " & t1 as string) & return) into logfile
do shell script "curl -o " & quoted form of POSIX path of destpath & " " & httpURL
set t2 to GetMilliSec
write_to_disk from (("Download complete at " & t2 as string) & return) into logfile
write_to_disk from "Download duration: " & t2 - t1 & " milliseconds" into logfile

on write_to_disk from theData into targetFile
	set ff to open for access file targetFile with write permission
	write theData to ff starting at eof
	close access ff
end write_to_disk