VintageRice

[CC][Release] - ftpChatUpload

Dec 7th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. --[[
  2.     CC ftpChatUpload
  3.     Uploads the game conversation to an FTP .txt file
  4.    
  5.     Created by VintageRice
  6.     Completed: December 7th 2013
  7. --]]
  8.  
  9. --Setting up the variables
  10. chatBox = peripheral.wrap("right")
  11. fileName = "tempLog"
  12. ftpSite = "ftp://[email protected]@91.208.99.4/public_html/ftp_items/ftbLog.txt"
  13. maxString = 50
  14.  
  15. --Recording the games chat
  16. function recordChat()
  17.     stringCount = 0
  18.     tempLog = fs.open(fileName, "a")
  19.    
  20.     while true do
  21.         term.clear()
  22.         term.setCursorPos(1, 1)
  23.        
  24.         print((maxString - stringCount).." strings until upload")
  25.        
  26.         if stringCount == maxString then
  27.             stringCount = 0
  28.             tempLog.close()
  29.             uploadLog()
  30.         end
  31.        
  32.         event, player, message = os.pullEvent("chat")
  33.        
  34.         if message ~= " " then
  35.             tempLog.writeLine("[ "..player.." ] "..message)
  36.             stringCount = stringCount + 1
  37.         end
  38.     end
  39. end
  40.  
  41. --Uploads to your ftp file
  42. function uploadLog()
  43.     term.clear()
  44.     term.setCursorPos(1, 1)
  45.    
  46.     if http.request() ~= true then
  47.         print("Error connecting to: "..ftpSite)
  48.         sleep(1000)
  49.         recordChat()
  50.     else
  51.         print("Reading contents of: "..fileName)
  52.        
  53.         getContents = fs.open(fileName, "r")
  54.         toUpload = getContents.readAll()
  55.         getContents.close()
  56.        
  57.         print("Uploading to: "..ftpSite)
  58.         http.post(ftpSite, "data="..textutils.urlEncode(tostring(toUpload)))
  59.  
  60.         recordChat()
  61.     end
  62. end
  63.  
  64. recordChat()
Advertisement
Add Comment
Please, Sign In to add comment