Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --A simple FileSharing Client
- --For CC In-Game
- --(c) 2021 by Christopher Yarch
- --a.k.a Dusk The Dragon
- args = {...}
- modem = "back"
- rednet.open(modem)
- domain = "fileserver"
- if args[1] == "get" then
- local packet = {}
- table.insert(packet,"get")
- table.insert(packet,args[2])
- rednet.broadcast(packet,domain)
- id, msg = rednet.receive(domain,5)
- if not msg then
- print("Timed Out on Get")
- else
- if msg == "Err400" then
- print("Bad Request")
- elseif msg == "Err404" then
- print("Invalid ID")
- else
- f = fs.open(args[3],"w")
- f.write(msg)
- f.close()
- print("File received and written")
- end
- end
- elseif args[1] == "put" then
- if fs.exists(args[2]) then
- f = fs.open(args[2],"r")
- data = f.readAll()
- f.close()
- local packet = {}
- table.insert(packet,"put")
- table.insert(packet,data)
- rednet.broadcast(packet,domain)
- id,msg = rednet.receive(domain,5)
- if not msg then
- print("Time Out on Put")
- else
- if msg == "Err400" then
- print("Bad Request")
- else
- print("File Shared: "..msg)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement