Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function printUsage()
- print( "Usages:" )
- print( "downloadFile <url_file> <name>")
- end
- local tArgs = { ... }
- if #tArgs < 2 then
- printUsage()
- return
- end
- if not http then
- printError( "DownloadFile Api require http Api" )
- end
- local function get(url)
- print( "Connecting to " .. url)
- local response = http.get(url)
- if response then
- print( "Success to connect at " .. url)
- local sResponse = response.readAll()
- reponse.close()
- return sResponse
- else
- printError( "Failed to load " .. url)
- end
- end
- local function writeFile( url, nameFile )
- if url then
- local reponse = get(url)
- local file = fs.open(nameFile, "w")
- file.write(reponse)
- file.close()
- end
- end
- if #tArgs == 3 then
- writeFile(tArgs[1], tArgs[2])
- elseif #tArgs == 2 then
- writeFile(tArgs[1], tArgs[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement