Posted 21 July 2015 - 10:37 AM
Hi,
I found a topic already about this but it wasn't clear how to use it.
I am trying to make a program that will download the files. I have got to the point where it is successfully connecting to the website and downloading and saving the file but it returns as a HTML document.
Now, I do not want to use pastebin because it is easier to download from my website / DropBox.
Thanks in advance,
ZiR
EDIT: Here is the code:
I found a topic already about this but it wasn't clear how to use it.
I am trying to make a program that will download the files. I have got to the point where it is successfully connecting to the website and downloading and saving the file but it returns as a HTML document.
Now, I do not want to use pastebin because it is easier to download from my website / DropBox.
Thanks in advance,
ZiR
EDIT: Here is the code:
Spoiler
local tArgs = {...}
local function get(url)
write( "Connecting to the website..." )
local response = http.get(
url
)
if response then
print("Success")
local sResponse = response.readAll()
response.close()
return sResponse
else
printError( "Failed." )
end
end
local function printUsage()
error("Usage: "..shell.getRunningProgram().." <get> <url> <fileName>" , 0 )
end
local sCommand = tArgs[1]
if sCommand == "get" then
if #tArgs < 3 then
printUsage()
return
end
local sURL = tArgs[2]
local sFile = tArgs[3]
local sPath = shell.resolve( sFile )
if fs.exists( sPath ) then
print( "File already exists" )
return
end
local res = get( sURL )
if res then
local file = fs.open( sPath, "w" )
file.write( res )
file.close()
print( "Downloaded as "..sFile )
end
end
Edited on 21 July 2015 - 08:54 AM