Posted 27 September 2012 - 04:05 AM
Rednet file sender
Send files over rednet!
Links:
Pastebin get command:
http/pastebin get tPcBmegZ receivefile
http/pastebin get jNTTcdH5 sendfile
Raw code:
ReceiveFile:
Spoiler
term.clear()
term.setCursorPos(1,1)
local sides = {"left","right","top","bottom","back","front"}
for i=1,#sides do
if not rednet.isOpen(sides[i]) then
rednet.open(sides[i])
end
end
while true do
id,msg = rednet.receive()
if msg == "RECEIVE" then
id2,msg2 = rednet.receive()
f = fs.open(msg2, "w")
id3,msg3 = rednet.receive()
f.write(msg3)
f.close()
print("File "..msg2.." received!")
end
end
SendFile:
Spoiler
local args = {...}
local sides = {"top","bottom","back","front","left","right"}
for i=1,#sides do
if not rednet.isOpen(sides[i]) then
rednet.open(sides[i])
end
end
term.setCursorPos(1,1)
term.clear()
if #args < 1 then
print("Usage (<> required, [] optional):")
print("sendfile [ComputerID] <file>")
return
end
if #args == 1 then
if fs.exists(args[1]) then
textutils.slowPrint("Sending file "..args[1].."!")
rednet.broadcast("RECEIVE")
rednet.broadcast(args[1])
file = fs.open(args[1], "r")
rednet.broadcast(file.readAll())
file.close()
else
print(args[1].." does not exist!")
return
end
else
if fs.exists(args[2]) then
textutils.slowPrint("Sending file "..args[2].." to "..args[1])
F = fs.open(args[2])
id = tonumber(args[1])
rednet.send(id, "RECEIVE")
rednet.send(id, args[2])
rednet.send(id, F.readAll())
F.close()
else
print(args[2].." does not exist!")
return
end
end
Usage:
ReceiveFile:
Just type this then you can send the files!
SendFile [ComputerID] <File>:
"[ComputerID]" is completly optional but is used to send the file to a specific computer.
"<File>" is the file you want to send, and is manditory (of course).