Advertisement
Guest User

send

a guest
Aug 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local args = {...}
  2. local sides = {"back"}
  3. for i=1,#sides do
  4.  if not rednet.isOpen(sides[i]) then
  5.   rednet.open(sides[i])
  6.  end
  7. end
  8. term.setCursorPos(1,1)
  9. term.clear()
  10. if #args < 1 then
  11.  print("Usage (<> required, [] optional):")
  12.  print("sendfile [ComputerID] <file>")
  13.  return
  14. end
  15.  
  16. if #args == 1 then
  17.  if fs.exists(args[1]) then
  18.   textutils.slowPrint("Sending file "..args[1].."!")
  19.   rednet.broadcast("RECEIVE", "ftp")
  20.   rednet.broadcast(args[1], "ftp")
  21.   file = fs.open(args[1], "r")
  22.   rednet.broadcast(file.readAll(), "ftp")
  23.   file.close()
  24.  else
  25.   print(args[1].." does not exist!")
  26.   return
  27.  end
  28. else
  29.  if fs.exists(args[2]) then
  30.   textutils.slowPrint("Sending file "..args[2].." to "..args[1])
  31.   F = fs.open(args[2])
  32.   id = tonumber(args[1])
  33.   rednet.send(id, "RECEIVE", "ftp")
  34.   rednet.send(id, args[2], "ftp")
  35.   rednet.send(id, F.readAll(), "ftp")
  36.   F.close()
  37.  else
  38.   print(args[2].." does not exist!")
  39.   return
  40.  end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement