Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not fs.isDir("shared") then
- fs.delete("shared")
- fs.makeDir("shared")
- end
- function share()
- sleep(0.5)
- while true do
- for i,v in pairs(fs.list("shared")) do
- fUpdateTS = fs.open("shared/"..v,"r")
- fContents = fUpdateTS.readAll()
- fUpdateTS.close()
- uTS = v.." "..fContents.." FILE UPDATE"
- ftpmodem.transmit(51500,51500, uTS)
- sleep(0.05)
- end
- sleep(30)
- end
- end
- function main()
- term.clear()
- term.setCursorPos(1,1)
- shell.run("shell")
- end
- function rFiles()
- sides = {"top","bottom","left","right","front","back"}
- fModem = 0
- for a = 1, #sides do
- if peripheral.getType(sides[a]) == "modem" then
- ftpmodem = peripheral.wrap(sides[a])
- fModem = 1
- end
- end
- if fModem then
- ftpmodem.open(51500)
- while true do
- local e,s,fchan,rchan,msg,dist = os.pullEvent("modem_message")
- if string.find(msg, "FILE UPDATE") and fchan == 51500 then
- nFile = string.gsub(msg, "FILE UPDATE", "")
- wc = 0
- for w in string.gmatch(nFile, "%S+") do
- wc = wc+1
- fName = w
- break
- end
- local nFile = string.sub(nFile, #fName+2, #nFile)
- fUpdate = fs.open("shared/"..fName,"w")
- fUpdate.write(nFile)
- fUpdate.close()
- end
- end
- else
- printError("No modem present")
- end
- end
- parallel.waitForAny(share, main,rFiles)
Advertisement
Add Comment
Please, Sign In to add comment