svennp

wget

Oct 14th, 2012
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.58 KB | None | 0 0
  1. args = {...}
  2.  
  3. if args[1] == nil or args[2] == nil then
  4.   return print ("usage: "..shell.getRunningProgram().." <url> <name>")
  5. end
  6.  
  7. check = string.sub(args[1], 1, 7)
  8. if check == "http://" then
  9.   args[1] = string.sub(args[1], 8, #args[1])
  10. end
  11.  
  12. http.request("http://"..args[1])
  13. event,url,source = os.pullEvent()
  14. if event == "http_success" then
  15.     text = source.readAll()
  16.     if fs.exists(args[2]) then
  17.         fs.delete(args[2])
  18.     end
  19.     file = fs.open(args[2], "w")
  20.     file.write(text)
  21.     file.close()
  22.     print("downloaded as "..args[2])
  23. elseif event == "http_failure" then
  24.   print "error"
  25. end
Advertisement
Add Comment
Please, Sign In to add comment