Advertisement
the_lad

CCFTPServer

Jan 24th, 2021
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. --vars
  2. tbl = {}
  3. --functions
  4. function Init()
  5.   rn = fs.open(".rnconfig", 'r')
  6.   rednet.open(rn.readAll())
  7.  
  8.   if rednet.isOpen() then
  9.   print("Rednet Open")
  10.   return true
  11.   else
  12.   print("Rednet closed, contact systems manager to resolve")
  13.   return false
  14.   end
  15. end
  16.  
  17. function Log(data1,data2,data3)
  18.   local log = fs.open(".log", "a")
  19.   log.writeLine(data1..data2,data3)
  20.   log.close()
  21. end
  22.  
  23. function getInput()
  24.   print("Waiting:")
  25.   local client, message, protocol = rednet.receive("ftp")
  26.   Log(client, message, protocol)
  27.   print(client..message..protocol)
  28.   --analysis of data
  29.   for i=0, #tbl do
  30.     table.remove(tbl, i)
  31.   end
  32.   for w in string.gmatch(message, "%a+") do
  33.     table.insert(tbl, w)
  34.   end
  35.  
  36.   if tbl[1] == "getFile" then
  37.     local gFile = fs.open(tbl[2], "r")
  38.     rednet.send(client, gFile.readAll(), "ftp")
  39.     gFile.close()
  40.   elseif tbl[1] == "sendFile" then
  41.     local sFile = fs.open(tbl[2], "w")
  42.     local cli, data, prot = rednet.receive("ftp")
  43.     sFile.write(data)
  44.     sFile.close()
  45.   end
  46.   getInput()
  47. end
  48. --init sequence
  49. Init()
  50. term.clear()
  51. term.setCursorPos(1,1)
  52. getInput()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement