nonogamer9

WGET for 1.7.10

Jun 23rd, 2025 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. -- wget substitute for ComputerCraft 1.7.10
  2. local tArgs = {...}
  3. if #tArgs < 2 then
  4. print("Usage: wget <url> <filename>")
  5. return
  6. end
  7.  
  8. if not http then
  9. printError("wget requires http API")
  10. printError("Set http_enable to true in ComputerCraft.cfg")
  11. return
  12. end
  13.  
  14. local url = tArgs[1]
  15. local filename = tArgs[2]
  16. local path = shell.resolve(filename)
  17.  
  18. if fs.exists(path) then
  19. print("File already exists")
  20. return
  21. end
  22.  
  23. write("Connecting to "..url.." ... ")
  24. local response = http.get(url)
  25. if not response then
  26. print("Failed.")
  27. return
  28. end
  29.  
  30. print("Success.")
  31. local contents = response.readAll()
  32. response.close()
  33.  
  34. local file = fs.open(path, "w")
  35. file.write(contents)
  36. file.close()
  37. print("Downloaded as "..filename)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment