Alyssa

Share_Files

Nov 1st, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. if not fs.isDir("shared") then
  2.  fs.delete("shared")
  3.  fs.makeDir("shared")
  4. end
  5.  
  6. function share()
  7.     sleep(0.5)
  8.     while true do
  9.         for i,v in pairs(fs.list("shared")) do
  10.             fUpdateTS = fs.open("shared/"..v,"r")
  11.             fContents = fUpdateTS.readAll()
  12.             fUpdateTS.close()
  13.             uTS = v.." "..fContents.." FILE UPDATE"
  14.             ftpmodem.transmit(51500,51500, uTS)
  15.             sleep(0.05)
  16.         end
  17.         sleep(30)
  18.     end
  19. end
  20.  
  21. function main()
  22.     term.clear()
  23.     term.setCursorPos(1,1)
  24.     shell.run("shell")
  25. end
  26.  
  27. function rFiles()
  28.     sides = {"top","bottom","left","right","front","back"}
  29.     fModem = 0
  30.     for a = 1, #sides do
  31.         if peripheral.getType(sides[a]) == "modem" then
  32.             ftpmodem = peripheral.wrap(sides[a])
  33.             fModem = 1
  34.         end
  35.     end
  36.     if fModem then
  37.         ftpmodem.open(51500)
  38.         while true do
  39.             local e,s,fchan,rchan,msg,dist = os.pullEvent("modem_message")
  40.             if string.find(msg, "FILE UPDATE") and fchan == 51500 then
  41.                 nFile = string.gsub(msg, "FILE UPDATE", "")
  42.                 wc = 0
  43.                 for w in string.gmatch(nFile, "%S+") do
  44.                     wc = wc+1
  45.                     fName = w
  46.                     break
  47.                 end
  48.                 local nFile = string.sub(nFile, #fName+2, #nFile)
  49.                 fUpdate = fs.open("shared/"..fName,"w")
  50.                 fUpdate.write(nFile)
  51.                 fUpdate.close()
  52.             end
  53.         end
  54.     else
  55.         printError("No modem present")
  56.     end
  57. end
  58. parallel.waitForAny(share, main,rFiles)
Advertisement
Add Comment
Please, Sign In to add comment