Let's break it down, shall we?
if sCommand == "put" then
-- Upload a file to pastebin.com
-- Determine file to upload
local sFile = tArgs[2]
local sPath = shell.resolve( sFile )
if not fs.exists( sPath ) or fs.isDir( sPath ) then
print( "No such file" )
return
end
Bla bla bla, determining where the file is
-- Read in the file
local sName = fs.getName( sPath )
local file = fs.open( sPath, "r" )
local sText = file.readAll()
file.close()
Reading the contents of the file
-- POST the contents to pastebin
write( "Connecting to pastebin.com... " )
local key = "0ec2eb25b6166c0c27a394ae118ad829"
local response = 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).."&"..
"api_paste_code="..textutils.urlEncode(sText)
)
POSTing the contents to pastebin's API, store the result
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" )
if we got a response, read the string returned and match all characters from the end of the string that are not a slash (/) The string will look something like this: "
http://www.pastebin.com/eaf465", from which string.match gets "eaf465".
else
print( "Failed." )
end
If we didn't get a response, the file wasn't uploaded!