Advertisement
PaymentOption

Untitled

Aug 20th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. tArgs = { ... } -- Get the arguments passed by the user.
  2. bCheckpointsPassed = false; -- True if we should continue with attempting to download the file, false otherwise.
  3.  
  4. if #tArgs < 2 then
  5. print( "Useage: dropbox <link> <filename>" )
  6. else
  7. bCheckpointsPassed = true; -- There are enough arguments to proceed.
  8. end
  9.  
  10. if fs.exists( tArgs[2] ) and bCheckpointsPassed then
  11. print( "File already exists." )
  12. bCheckpointsPassed = false; -- The file does not exist and therefore we shall not proceed.
  13. end
  14.  
  15. -- If we're all clear to attempt to download this file.
  16. if bCheckpointsPassed then
  17. while true do
  18. local Response = http.get( -- Request the file through the link passed as an argument.
  19. "https://www.dropbox.com/s/" .. tArgs[1]
  20. )
  21.  
  22. if Response then -- If we got some sort of a response, or the variable is just not nil.
  23. print( "Success. Downloaded as " .. tArgs[2] )
  24. -- Write the response to the file. --
  25. local file = fs.open( tArgs[2], "w" )
  26. file.write( Response.readAll() )
  27. file.close()
  28.  
  29. break
  30. else -- There was no response; the request timed out.
  31. print( "Failure." )
  32. break
  33. end
  34. end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement