Advertisement
madpond

listening-ftp-rip

Feb 20th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. --Madpondia Inc.
  2. --A bug with similar coding to IRC will result in chat appearing in console window
  3. local side='right' -- Rednet side
  4. local name='test' -- Server name
  5.  
  6. wait=5
  7.  
  8. if fs.exists('/ftp')==false then
  9. fs.makeDir('/ftp')
  10. end
  11.  
  12. function split(pString, pPattern)
  13. local Table = {} -- NOTE: use {n = 0} in Lua-5.0
  14. local fpat = "(.-)" .. pPattern
  15. local last_end = 1
  16. local s, e, cap = pString:find(fpat, 1)
  17. while s do
  18. if s ~= 1 or cap ~= "" then
  19. table.insert(Table,cap)
  20. end
  21. last_end = e+1
  22. s, e, cap = pString:find(fpat, last_end)
  23. end
  24. if last_end <= #pString then
  25. cap = pString:sub(last_end)
  26. table.insert(Table, cap)
  27. end
  28. return Table
  29. end
  30. term.clear()
  31. term.setCursorPos((term.getSize()/2)-13,1)
  32. print('Iomega Service Listener')
  33. print('--------------------------------------------------')
  34. print('Allow 10 seconds for services to start!')
  35. rednet.open(side)
  36. while true do
  37. id,res=rednet.receive(wait)
  38. if res == nil then
  39. if wait==5 then
  40. print('--------------------------------------------------')
  41. wait=wait+60
  42. end
  43. else
  44. wait=5
  45. print(id..'->'..res)
  46. res=split(res,'\:')
  47. if res[1]=='ftp' and res[2]==name then
  48. if res[3]=='id' then
  49. rednet.send(id,'')
  50. elseif res[3]=='get' then
  51. fl=''
  52. fnf='File Not Found'
  53. if res[4]==nil then
  54. out=fnf
  55. else
  56. fl='/ftp/'..res[4]
  57. end
  58. if fs.exists(fl) and fs.isDir(fl)==false then
  59. file=fs.open(fl,'r')
  60. out=file.readAll()
  61. file.close()
  62. else
  63. out=fnf
  64. end
  65. rednet.send(id,out)
  66. elseif res[3]=='set' then
  67. fl=''
  68. if res[4]==nil then
  69. rednet.send(id,'INVALID')
  70. else
  71. fl='/ftp/'..res[4]
  72. end
  73. if fs.exists(fl)==false then
  74. rednet.send(id,'OK')
  75. id2,rec=rednet.receive(10)
  76. if id2==id then
  77. file=fs.open(fl,'w')
  78. out=file.write()
  79. file.close()
  80. end
  81. else
  82. rednet.send(id,'EXISTS')
  83. end
  84. elseif res[1]== "ikilltheworld" then --Not Currently working, Useage, Server
  85. --Control from central console
  86. --Plan to have a dedicated console, with access methods only usable
  87. --by certain logins, For the mean TIME, DO NOT TOUCH THIS MODULE
  88. os.shutdown()
  89. elseif res[3]=='ls' then
  90. lst={}
  91. out=''
  92. if res[4]==nil then
  93. lst='/ftp'
  94. else
  95. lst='/ftp/'..res[4]
  96. end
  97. if fs.exists(lst) and fs.isDir(lst) then
  98. lst2=fs.list(lst)
  99. for k,v in ipairs(lst2) do
  100. if fs.isDir(lst..'/'..v) then
  101. out=out..'\nD '
  102. else
  103. out=out..'\nF '
  104. end
  105. out=out..v
  106. end
  107. else
  108. out='\nDirectory does not exist'
  109. end
  110. if out=='' then out='\nNo Files Found' end
  111. if not res[4]==nil then
  112. out=res[4]..out
  113. end
  114.  
  115. rednet.send(id,'File listing: '..out)
  116. end
  117. end
  118. end
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement