Advertisement
willwac

DropX Client

Nov 27th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. --[[ Developer's Notes: It was fun trying to break the program! Anyway, this
  2. is based on Egor305's FileServ, I just made it better, and added around 30
  3. more lines.]] for _, s in pairs(rs.getSides()) do     if
  4. peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
  5. rednet.open(s)     end end local serverid = 27 --change! local id, msg local
  6. args={...} local program = "client" --change! local function get()     repeat
  7. id,msg = rednet.receive(5)     until id == serverid or id == nil     print(msg
  8. or error("Cannot Reach Server",0)) end
  9.  
  10. if #args < 1 or #args > 4 then
  11.     print("\nDropX Usage:\n")
  12.     print(program.." put <local_file>")
  13.     print(program.." get [id] <server_file> <local_name>")
  14.     print(program.." dir [id]")
  15.     print(program.." del <server_file>")
  16.     print("Made by: willwac")
  17.     return
  18. end
  19.  
  20. if args[1] == "send" or args[1] == "put" then
  21.     if 1>#args or #args>3 then
  22.         print("Usage:\n "..program.." put <local_file>")
  23.         return
  24.     end
  25.     if not fs.exists(shell.resolve(args[2])) or fs.isDir(shell.resolve(args[2])) then
  26.         printError("No such file!")
  27.         return
  28.     end
  29.     theirFile=fs.open(shell.resolve(args[2]),"r")
  30.     if not args[3] then args[3] = args[2] end
  31.     rednet.send(serverid,"@put~!DSX!~"..args[3].."~!DSX!~"..theirFile.readAll())
  32.     theirFile.close()
  33.     get()
  34. elseif args[1] == "get" then
  35.     if #args == 3 then
  36.         args[4] = args[3]
  37.         args[3] = args[2]
  38.         args[2] = os.getComputerID()
  39.     end
  40.     if #args < 3 then
  41.         print("Usage:\n "..program.." get [id] <server_file> <local_name>")
  42.         return
  43.     end
  44.     rednet.send(serverid,"@get~!DSX!~"..args[2].."~!DSX!~"..args[3])
  45.     repeat
  46.         id,msg = rednet.receive(5)
  47.     until id == serverid or id == nil
  48.     if not id or not msg then error("Cannot Reach Server",0) end
  49.     theirFile=fs.open(args[4],"w")
  50.     if not theirFile then error("Could not open "..args[4].."! Try rebooting the computer.",0) end
  51.     theirFile.write(msg)
  52.     theirFile.close()
  53.     print("Saved to: "..args[4])
  54. elseif args[1] == "dir" or args[1] == "list" or args[1] == "ls" then
  55.     if #args > 2 then
  56.         print("Usage:\n "..program.." dir [id]")
  57.         return
  58.     end
  59.     if args[2] then
  60.         rednet.send(serverid,"@list~!DSX!~"..args[2])
  61.     else
  62.         rednet.send(serverid,"@list~!DSX!~")
  63.     end
  64.     repeat
  65.         id,msg = rednet.receive(5)
  66.     until id == serverid or id == nil
  67.     if id == nil then print("Cannot Reach Server") return end
  68.     textutils.pagedTabulate(textutils.unserialize(msg))
  69. elseif args[1] == "del" or args[1] == "delete" then
  70.     if #args > 2 or #args==1 then
  71.         print("Usage:\n "..program.." del <server_file>\nNote: Cannot delete multiple files.")
  72.         return
  73.     end
  74.     rednet.send(serverid,"@delete~!DSX!~"..args[2])
  75.     get()
  76. else
  77.     print("DropX Usage:")
  78.     print(program.." put <local_file>")
  79.     print(program.." get [id] <server_file> <local_name>")
  80.     print(program.." dir [id]")
  81.     print(program.." del <server_file>")
  82.     print("Made by: willwac")
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement