ohmaga

downloadnbs

Jul 31st, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. if not http then
  2. print("HTTP API is disabled")
  3. return false
  4. end
  5. local destination = "song"
  6. local url = ({...})[1]
  7. local httpHandle = http.get(url)
  8. if not httpHandle then
  9. print("Error downloading file")
  10. return false
  11. end
  12. if not fs.exists(destination) then fs.makeDir(destination) end
  13. if not fs.isDir(destination) then
  14. print("Destination must be a directory")
  15. return false
  16. end
  17. local fileHandle = fs.open(destination .. "/" .. fs.getName(url), "w")
  18. if not fileHandle then
  19. print("Error opening file")
  20. return false
  21. end
  22. fileHandle.write(httpHandle.readAll())
  23. httpHandle.close()
  24. fileHandle.close()
  25. print("Done")
Add Comment
Please, Sign In to add comment