This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
stilldabomb's profile picture

Rednet file sender!

Started by stilldabomb, 27 September 2012 - 02:05 AM
stilldabomb #1
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).
RedstonersElite #2
Posted 03 June 2013 - 10:05 PM

local sides = {"left","right","top","bottom","back","front"}
I've found that if you did this it would require a modem on all sides i am a bran new coder to CC but if you remove all of them except for one side it would work fine, Also if i tried to send a file to a computer i get
sendfile:31:31 Expected string, string
Could you possibly fix that i have tried myself but like i said new coder.
TheOddByte #3
Posted 06 June 2013 - 07:36 PM

local sides = {"left","right","top","bottom","back","front"}
I've found that if you did this it would require a modem on all sides i am a bran new coder to CC but if you remove all of them except for one side it would work fine, Also if i tried to send a file to a computer i get
sendfile:31:31 Expected string, string
Could you possibly fix that i have tried myself but like i said new coder.

This should be on line 31

F = fs.open(args[2],"r")
jesusthekiller #4
Posted 07 June 2013 - 04:56 AM
Something like:

print("Side: arg 1, file: arg 2")
local args = {...}
local m = peripheral.wrap(args[1]) or error("Error! Wrong side!")
m.broadcast(fs.open(args[2]).readAll() or error("Error while reading file!"))

Note: untested, written in browser :P/>
Nic #5
Posted 15 July 2013 - 09:31 PM
do you mind if i use this program in my program im makeing a notepad/data base over rednet so you can read files and edit them
TheOddByte #6
Posted 16 August 2013 - 11:21 AM
Why don't you open the modems like this?

for _,side in pairs(rs.getSides()) do
   if peripheral.getType(side) == "modem" then
     rednet.open(side)
end
  end
Mitchfizz05 #7
Posted 17 August 2013 - 05:45 AM
I made something like this a while back, I called it Bluetooth.
cmckain14 #8
Posted 21 August 2013 - 09:39 PM
Good stuff here!