""" download.cobra Downloads a file specified by a URL to the local file system. Windows: > cd \path\to\directory\of\download.cobra > cobra -c download.cobra > download http://www.google.com/images/logo_sm.gif Downloading http://www.google.com/images/logo_sm.gif to logo_sm.gif Done. Unix-like: > cd /path/to/directory/of/download.cobra > cobra -c Download.cobra > mono download.exe http://www.google.com/images/logo_sm.gif Downloading http://www.google.com/images/logo_sm.gif to logo_sm.gif Done. You can specify the local filename: > download http://www.google.com/images/logo_sm.gif GoogleLogo.gif Downloading http://www.google.com/images/logo_sm.gif to GoogleLogo.gif Done. """ use System.Net class DownloadFile def main args = CobraCore.commandLineArgs if args.count < 2 print 'usage: download URL \[LOCALFILENAME]' return url = args[1] # localFileName is derived from the url if missing: if args.count > 2 localFileName = args[2] else s = url if s.endsWith('/'), s = s[:-1] i = s.lastIndexOf('/') if i <> -1, localFileName = s[i+1:] else, print 'Invalid URL.' print 'Downloading [url] to [localFileName]' Console.out.flush try WebClient().downloadFile(url, localFileName) catch e as Exception print e print 'Done.'