Advertisement
Imgoodisher

Computercraft File Sharing Server

Feb 26th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. side = "back"
  2.  
  3. if fs.exists("bin/crazyapi")==false then
  4.  print("This program requires Crazyapi")
  5.  print("Installing crazyapi with cc-get...")
  6.  shell.run("cc-get", "install", "crazyapi")
  7. end
  8.  
  9. shell.run("crazyapi")
  10. networkOpen(side)
  11.  
  12. print("Server started")
  13. while true do
  14.  id, m = networkIDReceive()
  15.  cmd = string.sub(m, 1, 5)
  16.  arg = string.sub(m, 6)
  17.  print(id.." did "..cmd)
  18.  if cmd == "!!get" then
  19.   file = io.open(arg, "r")
  20.   data = file:read("*a")
  21.   file:close()
  22.   networkSendToID(id, data)
  23.  elseif cmd == "sendd" then
  24.   name = networkReceive()
  25.   if fs.exists(name) then fs.delete(name) end
  26.   if name == "startup" then networkSendToID(id, "Error: Name Not Allowed")
  27.   else
  28.    file = io.open(name, "w")
  29.    file:write(arg)
  30.    file:close()
  31.    networkSendToID(id, "Success")
  32.   end
  33.  elseif cmd == "!list" then
  34.   tFiles = fs.list("")
  35.   tFiles2 = {}
  36.   for i,v in pairs(tFiles) do
  37.    if fs.isDir(v)==false and v~="server" then
  38.     table.insert(tFiles2, v.."\n")
  39.    end
  40.   end
  41.   data = table.concat(tFiles2)
  42. --  print(data)
  43.   networkSendToID(id, data)
  44.  end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement