Advertisement
Lyqyd

nsh put

Jan 10th, 2013
698
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: put <local> <remote>")
  7.     print("<local>: any file on the client")
  8.     print("<remote>: any file on the server")
  9.     return
  10. end
  11.  
  12. local fileData = ""
  13.  
  14. nsh.send("FQ:;t="..args[1])
  15. local message = nsh.receive()
  16. if message ~= "fileNotFound" then
  17.     while true do
  18.         message = nsh.receive()
  19.         pType = string.sub(message, 1, 2)
  20.         if pType == "FD" then
  21.             fileData = fileData..string.match(message, "^FD:;t=(.*)")
  22.         elseif pType == "FE" then
  23.             break
  24.         end
  25.     end
  26.     if #fileData > 0 then
  27.         local handle = io.open(args[2], "w")
  28.         if handle then
  29.             handle:write(fileData)
  30.             handle:close()
  31.         end
  32.     else
  33.         print("Empty file not written!")
  34.     end
  35. end
Advertisement
RAW Paste Data Copied
Advertisement