Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- By tom2018 5/10/2013
- -- feel free to modify any part of this program
- -- just please send me a PM on the forums!
- --config
- side = "top" --modem
- rand = false --more secure not yet implemented
- btlp = false --not yet implement
- stpmsg = "end" --msg that indicates end of file
- shtdown = false -- if true will shutdown at end of file transfer
- gfb = true -- return current file size
- pmsg = "ping" --default ping msg
- --code
- rednet.open(side)
- term.clear()
- term.setCursorPos(1,1)
- print("tomsfiletranfer 0.1 |")
- print("by tom2018 |")
- print("---------------------#")
- print('Type help for command list')
- while true do
- ct = false
- write("action> ")
- p = read()
- if p == "help" then
- print[[help -cmd list
- exit -leave program
- id -computer id
- files -send file
- filer -receive file]]
- ct = true
- end
- if p == "id" then
- print(os.getComputerID())
- ct = true
- end
- if p == "filer" then
- write("ID> ")
- cid = read()
- stop = false
- cid = cid + 0
- write("save as: ")
- nami = read()
- h = fs.open(nami,"w")
- rednet.send(cid,"sup")
- while stop == false do
- icid, pack = rednet.receive(2)
- if icid == nil then
- print("no connection established")
- sleep(1.5)
- os.reboot()
- end
- if icid == cid then
- print("Received "..pack.." Saving to file")
- if pack ~= stpmsg then
- h.write(pack)
- if gfb == true then
- print(fs.getSize(nami))
- end
- else
- print("file complete!")
- stop = true
- h.close()
- if shtdown == true then
- os.shutdown()
- else
- os.reboot()
- end
- end
- elseif icid ~= nil then
- print("Blocked Conection from ID: "..icid)
- end
- sleep(0)
- end
- ct = true
- end
- if p == "files" then
- write("file> ")
- nami = read()
- h = fs.open(nami,"r")
- wpack = h.readAll()
- wpackt = {}
- print("Dividing into Packets may take a while!")
- for char in string.gmatch(wpack, ".") do
- table.insert(wpackt, char)
- sleep(0)
- end
- if gfb == true then
- print("hosting on "..os.getComputerID())
- eta = #wpackt * .01
- print("Estimated transfer time in seconds")
- print(eta)
- end
- while true do
- cid, auth = rednet.receive()
- stop = false
- c = 1
- wpn = #wpackt + 1
- if auth == "sup" then
- print("Seeding ID:"..cid)
- while c < wpn do
- rednet.send(cid, wpackt[c])
- c = c + 1
- sleep(0.01)
- end
- rednet.send(cid, stpmsg)
- print("Seed Complete!")
- elseif auth == pmsg then
- rednet.send(cid,nami)
- end
- sleep(0)
- end
- ct = true
- end
- if p == "exit" then
- print("Thankyou for using Tomsfiletransfer.")
- sleep(1.5)
- os.reboot()
- ct = true
- end
- if ct == false then
- print("Cmd not recongnized.")
- end
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement