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
rednet.open(modemSide)
--get message, no timeout
id, msg, dist = rednet.receive()
print("Data received!")
print("Received data:")
--get filename
term.write("Output filename: ")
name = tostring(read())
--decompress string
content = textutils.unserialize(msg)
--write to file
local file = fs.open(name, "w")
file.write(content)
--finish up
file.close()
rednet.close(modemSide)

View File

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