Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local internet = require("internet")
- local fs = require("filesystem")
- -- Function to download a file from Pastebin
- function downloadFromPastebin(pasteID, savePath)
- local url = "https://pastebin.com/raw/" .. pasteID
- -- Perform HTTP request to get the content of the Pastebin
- local response = internet.request(url)
- -- Check if request was successful
- if response then
- -- Open file for writing
- local file = io.open(savePath, "w")
- if file then
- -- Write content to file
- for chunk in response do
- file:write(chunk)
- end
- file:close()
- print("File downloaded successfully.")
- else
- print("Error: Could not open file for writing.")
- end
- else
- print("Error: Failed to fetch data from Pastebin.")
- end
- end
- -- Example usage
- local pasteID = "YOUR_PASTEBIN_ID_HERE"
- local savePath = "/path/to/save/file.txt"
- downloadFromPastebin(pasteID, savePath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement