Guest User

FTP Client

a guest
Dec 22nd, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. --run by running FTP Server on server machine at startup and type [FTP <file path> <save location>]
  2. rednet.open("left")
  3. filePath = {...}
  4. serverID = 10 --change to ID of server
  5. id = os.getComputerID()
  6. function requestFile()
  7.   PING = false
  8.   term.setCursorPos(1,1)
  9.   term.clear()
  10.   textutils.slowPrint("establishing connection...")
  11.   rednet.send(serverID, "CONNECTION","PING")
  12.   id, message = rednet.receive("PING")
  13.   if message == "RECIEVED" then
  14.     textutils.slowPrint("Connected.....")
  15.     files = tostring(filePath[1])
  16.     rednet.send(serverID, files,"FTP")
  17.     id, message = rednet.receive("FTP")
  18.     if message == "FILE FOUND" then
  19.       textutils.slowPrint(files.." found downloading now")
  20.       rednet.send(serverID,"DOWNLOADRQST","DOWNRQST")
  21.       recieveFile()
  22.     end  
  23.   end
  24. end
  25.  
  26. function recieveFile()
  27.   id, file = rednet.receive("Final")
  28.   print(file)
  29.   location = tostring(filePath[2])
  30.   newFile = fs.open(location, "w")
  31.   newFile.write(file)
  32.   print("recieved written to: "..location)
  33.   newFile.close()
  34.   sleep()
  35. end
  36.  
  37.  
  38. requestFile()
Advertisement
Add Comment
Please, Sign In to add comment