lukeplechaty

wifi-ftp

Jan 11th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. function neton()
  2. Open,FreeSide=false,nil
  3. for n,Side in pairs(rs.getSides())do   
  4. if peripheral.getType(Side)=="modem"then
  5. FreeSide=Side
  6. if rednet.isOpen(Side)then
  7. Open=true
  8. end
  9. end
  10. end
  11. if not Open then
  12. if FreeSide then
  13. rednet.open(FreeSide)
  14. else
  15. print("No modem attached")
  16. end
  17. end
  18. return true
  19. end
  20. function netoff()
  21. rednet.close(FreeSide)
  22. end
  23. function clear()
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. end
  27. function locator(acton,looking)
  28. line=0
  29. this=string.byte(looking)
  30. endline=string.len(acton)
  31. while true do
  32. if string.byte(acton,line)==this then
  33. return line
  34. end
  35. if line==endline then return end
  36. line=line+1
  37. end
  38. end
  39. a={...}
  40. id=(a[1])
  41. filename=(a[2])
  42. neton()
  43. if id==nil then
  44. clear()
  45. print("To Quit Push Q")
  46. print("ID: "..os.getComputerID())
  47. while true do
  48. z0,z1,z2=os.pullEvent()
  49. if z0=="rednet_message"then
  50. pos=locator(z2," ")
  51. name=tostring(string.sub(z2,1,pos-1))
  52. text=tostring(string.sub(z2,pos+1,string.len(z2)))
  53. file=io.open(name,"w")
  54. file:write(text)
  55. file:close()
  56. clear()
  57. print("Received: "..name)
  58. netoff()
  59. break
  60. end
  61. if z0=="char"then
  62. if z1=="q"then
  63. print("Stoping")
  64. sleep(1)
  65. netoff()
  66. sleep(1)
  67. clear()
  68. break
  69. end
  70. end
  71. end
  72. else
  73. file=io.open(filename,"r")
  74. text=file:read("*a")
  75. file:close()
  76. rednet.send(tonumber(id),filename.." "..text)
  77. clear()
  78. print("Sent: "..filename)
  79. netoff()
  80. end
Add Comment
Please, Sign In to add comment