Advertisement
Chickenbreadlp

ccFTP example Server

Jun 5th, 2016
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. --[[
  2.     Example Server Program for ccFTP API by Chickenbreadlp
  3. ]]
  4.  
  5.  -- Gets the arguments and checks if ccFTP is already present on the computer
  6. local tArgs = { ... }
  7. if fs.exists("/.ccftp/ccftp") then
  8.  os.loadAPI("/.ccftp/ccftp")
  9. else
  10.  fs.makeDir("/.ccftp")
  11.  shell.run("pastebin", "get", "8SxAwbQZ", "/.ccftp/ccftp")
  12.  os.loadAPI("/.ccftp/ccftp")
  13. end
  14.  
  15.  -- checking if the first argument
  16. if string.lower(tArgs[1]) == "runserver" then
  17.  print("Running Server with the following Hostname: "..tArgs[2])
  18.  while true do
  19.  
  20.  -- runs the ccFTP Server in return mode and sets the Hostname as the secon argument and the FTP-Share as the third
  21.  
  22.   local a, b, c, d = ccftp.runServer(tArgs[2], true, tArgs[3])
  23.  
  24.  -- if the Server returns something, it'll prit it on the screen
  25.  
  26.   print("Sender:   "..b)
  27.   if d == nil then d = c else
  28.   print("Request:  "..c) end
  29.   if a == true then
  30.    print("Argument: "..d)
  31.   else
  32.    print("Error:    "..d)
  33.   end
  34.   print(" ----")
  35.  end
  36. elseif string.lower(tArgs[1]) == "closeserver" then
  37.  
  38.  -- shuts down any running ccFTP host and gives the user a feedback
  39.  
  40.  local a = ccftp.closeServer()
  41.  if a == true then
  42.   print("Unhosted running ccFTP-Host")
  43.  else
  44.   printError("There wasn't any running ccFTP-Hosts!")
  45.  end
  46. elseif string.lower(tArgs[1]) == "cuser" then
  47.  
  48.  -- checks again if a sufficent amount of arguments are given and then creates a user; Username: second argument; Password: third argument
  49.  
  50.  if #tArgs >= 3 then
  51.   local res = ccftp.createUser(tArgs[2], tArgs[3])
  52.   if res == true then
  53.    print("User by the name "..tArgs[2].." created")
  54.   elseif res == "UsrE" then
  55.    printError("User already exists!")
  56.   end
  57.  else
  58.   printError("Not enought Arguments!")
  59.  end
  60. elseif string.lower(tArgs[1]) == "chguser" then
  61.  
  62.  -- checks again if a sufficent amount of arguments are given and then changes username from second argument to third argument; Password: third argument
  63.  
  64.  if #tArgs >= 4 then
  65.   local res = ccftp.renameUser(tArgs[2], tArgs[3], tArgs[4])
  66.   if res == true then
  67.    print("User renamed from "..tArgs[2].." to "..tArgs[3])
  68.   elseif res == "nsUsr" then
  69.    printError("User by the name "..tArgs[2].." does not exist!")
  70.   elseif res == "nUsrE" then
  71.    printError("A User by the name of "..tArgs[3].." does already exist!")
  72.   elseif res == "pww" then
  73.    printError("The entered password is wrong!")
  74.   end
  75.  else
  76.   printError("Not enought Arguments!")
  77.  end
  78. elseif string.lower(tArgs[1]) == "passwd" then
  79.  
  80.  -- checks again if a sufficent amount of arguments are given and then changes password from third argument to fourth argument; Username: third argument
  81.  
  82.  if #tArgs >= 4 then
  83.   local res = ccftp.changeUserPass(tArgs[2], tArgs[3], tArgs[4])
  84.   if res == true then
  85.    print("Password from User "..tArgs[2].." was changed")
  86.   elseif res == "nsUsr" then
  87.    printError("User by the name of "..tArgs[2].." does not exists!")
  88.   elseif res == "pww" then
  89.    printError("The entered password was wrong!")
  90.   end
  91.  else
  92.   printError("Not enought Arguments!")
  93.  end
  94. elseif string.lower(tArgs[1]) == "rmuser" then
  95.  
  96.  -- checks again if a sufficent amount of arguments are given and then removes user with the name of the second argument; password is third argument
  97.  
  98.  if #tArgs >= 3 then
  99.   local res = ccftp.removeUser(tArgs[2], tArgs[3])
  100.   if res == true then
  101.    print("User by the name of "..tArgs[2].." was removed!")
  102.   elseif res == "nsUsr" then
  103.    printError("There is no User by the name of "..tArgs[2])
  104.   elseif res == "pww" then
  105.    printError("Ther entered password is wrong!")
  106.   end
  107.  else
  108.   printError("Not enought Arguments!")
  109.  end
  110. else
  111.  
  112.  -- gives the user the usage if insufficent arguments are given
  113.  
  114.  printError([[Usage:
  115.  runserver 'hostname' (FTP-Share) -- Runs Server
  116.  closeserver -- Shuts down any running ccFTP-Hosts
  117.  cuser 'UserName' 'Password' -- creats new Account
  118.  chguser 'oldUserName' 'newUserName' 'Password' -- renames a User
  119.  passwd 'UserName' 'oldPassword' 'newPassword' -- changes a Password
  120.  rmuser 'UserName' 'Password' -- removes a User]])
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement