Advertisement
Derek1017

working ftp

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