Advertisement
tom2018

filetransfer

May 10th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. -- By tom2018 5/10/2013
  2. -- feel free to modify any part of this program
  3. -- just please send me a PM on the forums!
  4. --config
  5.  
  6. side = "top" --modem
  7. rand = false --more secure not yet implemented
  8. btlp = false --not yet implement
  9. stpmsg = "end" --msg that indicates end of file
  10. shtdown = false -- if true will shutdown at end of file transfer
  11. gfb = true -- return current file size
  12. pmsg = "ping" --default ping msg
  13.  
  14. --code
  15. rednet.open(side)
  16. term.clear()
  17. term.setCursorPos(1,1)
  18. print("tomsfiletranfer 0.1  |")
  19. print("by tom2018           |")
  20. print("---------------------#")
  21. print('Type help for command list')
  22.  
  23. while true do
  24. ct = false
  25. write("action> ")
  26. p = read()
  27.  
  28. if p == "help" then
  29. print[[help -cmd list
  30. exit -leave program
  31. id -computer id
  32. files -send file
  33. filer -receive file]]
  34. ct = true
  35. end
  36.  
  37. if p == "id" then
  38. print(os.getComputerID())
  39. ct = true
  40. end
  41.  
  42. if p == "filer" then
  43. write("ID> ")
  44. cid = read()
  45. stop = false
  46. cid = cid + 0
  47. write("save as: ")
  48. nami = read()
  49. h = fs.open(nami,"w")
  50. rednet.send(cid,"sup")
  51.  
  52. while stop == false do
  53. icid, pack = rednet.receive(2)
  54. if icid == nil then
  55. print("no connection established")
  56. sleep(1.5)
  57. os.reboot()
  58. end
  59. if icid == cid then
  60. print("Received "..pack.." Saving to file")
  61.  
  62. if pack ~= stpmsg then
  63. h.write(pack)
  64. if gfb == true then
  65. print(fs.getSize(nami))
  66. end
  67. else
  68. print("file complete!")
  69. stop = true
  70. h.close()
  71. if shtdown == true then
  72. os.shutdown()
  73. else
  74. os.reboot()
  75. end
  76. end
  77.  
  78. elseif icid ~= nil then
  79. print("Blocked Conection from ID: "..icid)
  80. end
  81. sleep(0)
  82. end
  83.  
  84. ct = true
  85. end
  86.  
  87. if p == "files" then
  88. write("file> ")
  89. nami = read()
  90. h = fs.open(nami,"r")
  91. wpack = h.readAll()
  92. wpackt = {}
  93.  
  94. print("Dividing into Packets may take a while!")
  95. for char in string.gmatch(wpack, ".") do
  96. table.insert(wpackt, char)
  97. sleep(0)
  98. end
  99.  
  100. if gfb == true then
  101. print("hosting on "..os.getComputerID())
  102. eta = #wpackt * .01
  103. print("Estimated transfer time in seconds")
  104. print(eta)
  105. end
  106.  
  107. while true do
  108.  
  109. cid, auth = rednet.receive()
  110. stop = false
  111. c = 1
  112. wpn = #wpackt + 1
  113. if auth == "sup" then
  114. print("Seeding ID:"..cid)
  115. while c < wpn do
  116. rednet.send(cid, wpackt[c])
  117. c = c + 1
  118. sleep(0.01)
  119. end
  120. rednet.send(cid, stpmsg)
  121. print("Seed Complete!")
  122.  
  123. elseif auth == pmsg then
  124. rednet.send(cid,nami)
  125. end
  126. sleep(0)
  127. end
  128.  
  129. ct = true
  130. end
  131.  
  132. if p == "exit" then
  133. print("Thankyou for using Tomsfiletransfer.")
  134. sleep(1.5)
  135. os.reboot()
  136. ct = true
  137. end
  138.  
  139. if ct == false then
  140. print("Cmd not recongnized.")
  141. end
  142. sleep(0)
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement