Improved file transfer scripts

This commit is contained in:
Hadinos Sanosam 2021-01-09 04:05:20 +01:00
parent e25e97b7cc
commit d643f4c77c
2 changed files with 17 additions and 4 deletions

View File

@ -1,18 +1,23 @@
dofile("utils") dofile("/git-scripts/utils")
modemSide = utils.getSideOf("modem") --get side the modem is on modemSide = utils.getSideOf("modem") --get side the modem is on
rednet.open(modemSide) rednet.open(modemSide)
--get message, no timeout --get message, no timeout
id, msg, dist = rednet.receive() id, msg, dist = rednet.receive()
print("Data received!")
print("Received data:") --get filename
term.write("Output filename: ") term.write("Output filename: ")
name = tostring(read()) name = tostring(read())
--decompress string --decompress string
content = textutils.unserialize(msg) content = textutils.unserialize(msg)
--write to file --write to file
local file = fs.open(name, "w") local file = fs.open(name, "w")
file.write(content) file.write(content)
--finish up
file.close() file.close()
rednet.close(modemSide) rednet.close(modemSide)

View File

@ -1,21 +1,28 @@
dofile("utils") dofile("utils")
modemSide = utils.getSideOf("modem")
--init rednet
modemSide = utils.getSideOf("modem")
rednet.open(modemSide) rednet.open(modemSide)
--get file content into right format
term.write("Path: ") term.write("Path: ")
path = tostring(read()) path = tostring(read())
local file = fs.open(path, "r") local file = fs.open(path, "r")
if file == nil then
print("File does not exist!")
return
end
content = file.readAll() content = file.readAll()
data = textutils.serialize(content) data = textutils.serialize(content)
--get receiver
term.write("Receiver id: ") term.write("Receiver id: ")
id = tonumber(read()) id = tonumber(read())
print("Initialize receiver please!") print("Initialize receiver please!")
print("Press 's' to send") print("Press 's' to send")
--wait for button press
local event, c = os.pullEvent("char") local event, c = os.pullEvent("char")
if c == "s" then if c == "s" then
print("Sending...") print("Sending...")
@ -25,4 +32,5 @@ else
print("Aborted.") print("Aborted.")
end end
--finish up
rednet.close(modemSide) rednet.close(modemSide)