Advertisement
Imgoodisher

Computercraft File Sharing Client

Feb 26th, 2012
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. serverid = 3
  2. side = "back"
  3.  
  4. if fs.exists("bin/crazyapi")==false then
  5.  print("This program requires crazyapi")
  6.  print("Installing crazyapi with cc-get...")
  7.  shell.run("cc-get", "install", "crazyapi")
  8. end
  9.  
  10. shell.run("crazyapi")
  11.  
  12. networkOpen(side)
  13.  
  14. while true do
  15.  clearTerm()
  16.  tOptions = {"Get file", "Send file", "List", "Exit"}
  17.  selected = selectWindow(1, 1, "What would you like to do?", tOptions, 1)
  18.  clearTerm()
  19.  if selected == 1 then
  20.   print("What file do you want to get?")
  21.   name = read()
  22.   print("Where do you want to save it?")
  23.   path = read()
  24.   networkSendToID(serverid, "!!get"..name)
  25.   data = networkReceive()
  26.   file = io.open(path, "w")
  27.   file:write(data)
  28.   file:close()
  29.   print("Done")
  30.   sleep(0.5)
  31.  elseif selected == 2 then
  32.   print("What file would you like to send?")
  33.   path = read()
  34.   print("What do you want the file to be named?")
  35.   name = read()
  36.   file = io.open(path, "r")
  37.   data = file:read("*a")
  38.   file:close()
  39.   networkSendToID(serverid, "sendd"..data)
  40.   networkSendToID(serverid, name)
  41.   print(networkReceive())
  42.  elseif selected == 3 then
  43.   networkSendToID(serverid, "!list")
  44.   print(networkReceive())
  45.   print("Press any key to continue")
  46.   pressAnyKey()
  47.  elseif selected == 4 then
  48.   shell.run("shell")
  49.  end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement