This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SP2's profile picture

[1.33+]Dropbox File Downloader

Started by SP2, 21 September 2012 - 02:59 AM
SP2 #1
Posted 21 September 2012 - 04:59 AM
I had access issues with Pastebin, so I couldn't use it. Therefore I wrote a little program to download files from Dropbox, mostly for convenience sakes.
So far, it has been tested on 1.33 and above.

Source:
Spoiler

local tVarargs = {...}
local sDropboxFilename = tVarargs[1]
local sLocalFilename = tVarargs[2]
local iDropboxUser = 0
--[[ Enter your dropbox user ID on the line above.
To get your ID copy a public link and it's the long
number after the /u/. ]]

if #tVarargs ~= 2 then
	print("Usage: dropbox [remote filename] [filename]")
	return
elseif not http then
	print("Please enable the HTTP API to used this program.")
	return
elseif iDropboxUser == 0 then
	print("Please edit this program and change the Dropbox ID on line 4 to your own ID.")
	return
end

local sVersion = string.sub(os.version(), -3)
local fileGet = {}
if sVersion == "1.4" then
	fileGet = http.get("https://dl.dropbox.com/u/" .. iDropboxUser .. "/" .. sDropboxFilename)
else
	fileGet = http.get("http://dl.dropbox.com/u/" .. iDropboxUser .. "/" .. sDropboxFilename)
end

if fs.exists(sLocalFilename) == true then
	fs.delete(sLocalFilename)
end

local tFile = fs.open(sLocalFilename, "w")
tFile.write(fileGet.readAll())
tFile.close()

fileGet.close()

Changelog:
SpoilerI know this isn't "standard" but oh well.

[indent=1]- Released.[/indent]
[indent=1]- Added some extra error checking and made it so it uses https if on the correct version of ComputerCraft.[/indent]
[indent=1]- Added some more error checking, mainly cause I keep forgetting to update the iDropboxUser variable and then it crashes.[/indent]
Usage: dropbox [remote filename] [filename].
Requirements: HTTP API needs to be enabled.
Download (or copy from above): https://dl.dropbox.c...ode/dropbox.lua
cant_delete_account #2
Posted 21 September 2012 - 05:54 AM
Those parentheses on the if statements were erroring for me, I fixed it if anyone wanted (also made it use HTTPS, but you need 1.4+ for that):

local tVarargs = {...}
local sDropboxFilename = tVarargs[1]
local sLocalFilename = tVarargs[2]
local iDropboxUser = 0 -- Enter your dropbox user ID here, to get your ID copy a public link and it's the long number after the /u/.
if #tVarargs ~= 2  then
print("Usage: dropbox [remote filename] [filename]")
return
end
local fileGet = http.get("https://dl.dropbox.com/u/" .. iDropboxUser .. "/" .. sDropboxFilename)
if fs.exists(sLocalFilename) == true then
fs.delete(sLocalFilename)
end
local tFile = fs.open(sLocalFilename, "w")
tFile.write(fileGet.readAll())
tFile.close()
fileGet.close()
SP2 #3
Posted 21 September 2012 - 06:12 AM
Strange, I had no errors in both 1.33 and 1.41. The reason it doesn't use https is because I needed it for Tekkit as well as my own modded version, but having the option is always good, so thanks.

EDIT: Changed it around a bit so that it should use https in 1.4
Edited on 21 September 2012 - 04:37 AM