Advertisement
Lyqyd

nsh get

Jan 10th, 2013
859
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if not nsh then print("No nsh session!") return end
  2.  
  3. local args = {...}
  4.  
  5. if #args < 2 then
  6.     print("Usage: get <remote> <local>")
  7.     print("<remote>: any file on the server")
  8.     print("<local>: any non-existant file on the client")
  9.     return
  10. end
  11.  
  12. if fs.exists(args[1]) then
  13.     nsh.send("FS:;t="..args[2])
  14.     local message = nsh.receive()
  15.     if message == "FR:;ok" then
  16.         nsh.send("FH:;"..args[1])
  17.         local handle = io.open(args[1], "r")
  18.         if handle then
  19.             nsh.send("FD:;t="..handle:read("*a"))
  20.             handle:close()
  21.         end
  22.         nsh.send("FE:;end")
  23.     else
  24.         print("Client rejected file!")
  25.     end
  26. end
Advertisement
RAW Paste Data Copied
Advertisement