SHARE
TWEET

client.lua

a guest Feb 18th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. args = {...}
  2. op = args[1]
  3. server_id = tonumber(args[2])
  4.  
  5. function split(inputstr, sep)
  6.     if sep == nil then
  7.         sep = "%s"
  8.     end
  9.     local t={}
  10.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  11.         table.insert(t, str)
  12.     end
  13.     return t
  14. end
  15.  
  16. function tablelength(T)
  17.     local count = 0
  18.     for _ in pairs(T) do count = count + 1 end
  19.     return count
  20. end
  21.  
  22. if op == "send" or op == "get" then
  23.     file = args[3]
  24. end
  25.  
  26. local present = false
  27. for _, side in pairs(rs.getSides()) do
  28.     if peripheral.getType(side) == "modem" then
  29.         present = true
  30.         rednet.open(side)
  31.     end
  32. end
  33.  
  34. if op == "list" then
  35.     rednet.send(server_id, "list:all", "FTP")
  36.     id, list = rednet.receive("FTP")
  37.     files = split(list, ":")
  38.     for i=1,tablelength(files) do
  39.         print(files[i])
  40.     end
  41. elseif op == "get" then
  42.     rednet.send(server_id, "get:" .. file, "FTP")
  43.     id, file_data = rednet.receive("FTP")
  44.     if file_data == "1" then
  45.         printError("file does not exsist on server")
  46.         return
  47.     end
  48.     file_table = split(file_data, ":*:")
  49.     file_name = file_table[1]
  50.     file_content = file_table[2]
  51.     if fs.exists(file_name) == true then
  52.         print("file alredy exsists")
  53.     else
  54.         file = fs.open(file_name, "w")
  55.         file.write(file_content)
  56.         file.close()
  57.     end
  58.     elseif op == "send" then
  59.         print("wip")
  60.    
  61. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top