Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = { ... } -- Get the arguments passed by the user.
- bCheckpointsPassed = false; -- True if we should continue with attempting to download the file, false otherwise.
- if #tArgs < 2 then
- print( "Useage: dropbox <link> <filename>" )
- else
- bCheckpointsPassed = true; -- There are enough arguments to proceed.
- end
- if fs.exists( tArgs[2] ) and bCheckpointsPassed then
- print( "File already exists." )
- bCheckpointsPassed = false; -- The file does not exist and therefore we shall not proceed.
- end
- -- If we're all clear to attempt to download this file.
- if bCheckpointsPassed then
- while true do
- local Response = http.get( -- Request the file through the link passed as an argument.
- "https://www.dropbox.com/s/" .. tArgs[1]
- )
- if Response then -- If we got some sort of a response, or the variable is just not nil.
- print( "Success. Downloaded as " .. tArgs[2] )
- -- Write the response to the file. --
- local file = fs.open( tArgs[2], "w" )
- file.write( Response.readAll() )
- file.close()
- break
- else -- There was no response; the request timed out.
- print( "Failure." )
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement