Advertisement
DOGGYWOOF

Open cpomputer pastebin downloader

Apr 27th, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. local component = require("component")
  2. local internet = require("internet")
  3. local fs = require("filesystem")
  4.  
  5. -- Function to download a file from Pastebin
  6. function downloadFromPastebin(pasteID, savePath)
  7. local url = "https://pastebin.com/raw/" .. pasteID
  8.  
  9. -- Perform HTTP request to get the content of the Pastebin
  10. local response = internet.request(url)
  11.  
  12. -- Check if request was successful
  13. if response then
  14. -- Open file for writing
  15. local file = io.open(savePath, "w")
  16. if file then
  17. -- Write content to file
  18. for chunk in response do
  19. file:write(chunk)
  20. end
  21. file:close()
  22. print("File downloaded successfully.")
  23. else
  24. print("Error: Could not open file for writing.")
  25. end
  26. else
  27. print("Error: Failed to fetch data from Pastebin.")
  28. end
  29. end
  30.  
  31. -- Example usage
  32. local pasteID = "YOUR_PASTEBIN_ID_HERE"
  33. local savePath = "/path/to/save/file.txt"
  34. downloadFromPastebin(pasteID, savePath)
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement