Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function printUsage() -- Program from ImGoodDisher , credits : http://pastebin.com/aZheqT4C
- print( "Usages:" )
- print( "pastebin put <filename>" )
- print( "pastebin get <code> <filename>" )
- end
- local tArgs = { ... }
- if #tArgs < 2 then
- printUsage()
- return
- end
- h = fs.open("Data","w")
- local sCommand = tArgs[1]
- if sCommand == "put" then
- -- Upload a file to pastebin.com
- -- Determine dir to upload
- local sFile = tArgs[2]
- if not fs.exists( sFile ) then
- print( "No such file or Dir" )
- return
- end
- t = fs.find(sFile.."/")
- for i =1,#t do
- sName[i] = fs.getName(t[i])
- -- Read in the file
- local file[i] = fs.open( t[i], "r" )
- local sText[i] = file.readAll()
- file[i].close()
- end
- -- Log in
- print("Log in? y/n")
- while true do
- login = read()
- if login == "y" or login == "n" then
- break
- end
- end
- if login == "y" then
- write("Username: ")
- username = textutils.urlEncode(read())
- write("Password: ")
- password = textutils.urlEncode(read("*"))
- end
- write( "Connecting to pastebin.com... " )
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- for 1,#t do
- if login == "y" then
- local userraw = http.post(
- "http://pastebin.com/api/api_login.php",
- "api_dev_key="..key.."&"..
- "api_user_name="..username.."&"..
- "api_user_password="..password
- )
- -- get user code in annoying roundabout way
- -- error/bug/?: userraw[1]() doesn't work
- for i,v in pairs(userraw) do
- user = v()
- break
- end
- -- check for errors with pastebin
- if string.sub(user, 1, 3) == "Bad" then print("\n"..user) error("") end
- local response[i] = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_user_key="..user.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName[i]).."&"..
- "api_paste_code="..textutils.urlEncode(sText[i])
- )
- print("Done "..i)
- else
- local response[i] = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName[i]).."&"..
- "api_paste_code="..textutils.urlEncode(sText[i])
- )
- end
- if response then
- print( "Success." )
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- print( "Uploaded as "..sResponse )
- print( "Run \"pastebin get "..sCode.."\" to download anywhere" )
- h.writeLine(sCode)
- else
- print( "Failed." )
- end
- end
Add Comment
Please, Sign In to add comment