· 4 years ago · Aug 04, 2021, 08:58 PM
1if not fs.exists("/fujiAPIs/redutils.lua") then
2 error("Needs redutils API at /fujiAPIs/redutils.lua")
3end
4if not fs.exists("/fujiAPIs/qtext.lua") then
5 error("Needs qtext API at fujiAPIs/qtext.lua")
6end
7-- Modem to use
8rednet.open("top")
9
10-- Introduction
11term.clear()
12term.setCursorPos(1, 1)
13qtext.tlit("RedNeT ", colors.red)
14print("File Sender")
15
16-- Set a hostname
17qtext.cursorOffset(0, 1)
18term.write("Hostname: ")
19local usinHostname = io.read()
20rednet.host("rnfsend", usinHostname)
21print("Registered hostname " .. usinHostname)
22print("Press any key to begin")
23os.pullEvent("key")
24os.sleep(0.1)
25
26-- Lookup
27term.clear()
28term.setCursorPos(1, 1)
29term.write("Hostname to send to: ")
30local usinHostLookup = io.read()
31local recHost = rednet.lookup("rnfsend", usinHostLookup)
32if not recHost then
33 qtext.tlit("Couldn't establish a connection", colors.red, true)
34 error("Didn't find a computer with hostname specified")
35end
36qtext.tlit("Established connection with " .. recHost, colors.green, true)
37term.write("Path of file: ")
38local fPath = io.read()
39local f = fs.open(fPath, "r")
40print("Sending file...")
41
42-- Main loop:
43-- 1. Read a line
44-- 2. If the line is nil, tell the
45-- receiver to finish and then end
46-- the program. Otherwise...
47-- 3. Tell the receiver to be ready
48-- to receive
49-- 4. Send the line
50while true do
51 local fLine = f.readLine()
52 if fLine then
53 rednet.send(recHost, "s", "rnfsend")
54 os.sleep(0.1)
55 rednet.send(recHost, fLine, "rnfsend")
56 else
57 rednet.send(recHost, "f", "rnfsend")
58 f.close()
59 print("File sent!")
60 break
61 end
62 redutils.sreceive("rnfsend", recHost)
63end
64
65rednet.close("top")