Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Example Server Program for ccFTP API by Chickenbreadlp
- ]]
- -- Gets the arguments and checks if ccFTP is already present on the computer
- local tArgs = { ... }
- if fs.exists("/.ccftp/ccftp") then
- os.loadAPI("/.ccftp/ccftp")
- else
- fs.makeDir("/.ccftp")
- shell.run("pastebin", "get", "8SxAwbQZ", "/.ccftp/ccftp")
- os.loadAPI("/.ccftp/ccftp")
- end
- -- checking if the first argument
- if string.lower(tArgs[1]) == "runserver" then
- print("Running Server with the following Hostname: "..tArgs[2])
- while true do
- -- runs the ccFTP Server in return mode and sets the Hostname as the secon argument and the FTP-Share as the third
- local a, b, c, d = ccftp.runServer(tArgs[2], true, tArgs[3])
- -- if the Server returns something, it'll prit it on the screen
- print("Sender: "..b)
- if d == nil then d = c else
- print("Request: "..c) end
- if a == true then
- print("Argument: "..d)
- else
- print("Error: "..d)
- end
- print(" ----")
- end
- elseif string.lower(tArgs[1]) == "closeserver" then
- -- shuts down any running ccFTP host and gives the user a feedback
- local a = ccftp.closeServer()
- if a == true then
- print("Unhosted running ccFTP-Host")
- else
- printError("There wasn't any running ccFTP-Hosts!")
- end
- elseif string.lower(tArgs[1]) == "cuser" then
- -- checks again if a sufficent amount of arguments are given and then creates a user; Username: second argument; Password: third argument
- if #tArgs >= 3 then
- local res = ccftp.createUser(tArgs[2], tArgs[3])
- if res == true then
- print("User by the name "..tArgs[2].." created")
- elseif res == "UsrE" then
- printError("User already exists!")
- end
- else
- printError("Not enought Arguments!")
- end
- elseif string.lower(tArgs[1]) == "chguser" then
- -- checks again if a sufficent amount of arguments are given and then changes username from second argument to third argument; Password: third argument
- if #tArgs >= 4 then
- local res = ccftp.renameUser(tArgs[2], tArgs[3], tArgs[4])
- if res == true then
- print("User renamed from "..tArgs[2].." to "..tArgs[3])
- elseif res == "nsUsr" then
- printError("User by the name "..tArgs[2].." does not exist!")
- elseif res == "nUsrE" then
- printError("A User by the name of "..tArgs[3].." does already exist!")
- elseif res == "pww" then
- printError("The entered password is wrong!")
- end
- else
- printError("Not enought Arguments!")
- end
- elseif string.lower(tArgs[1]) == "passwd" then
- -- checks again if a sufficent amount of arguments are given and then changes password from third argument to fourth argument; Username: third argument
- if #tArgs >= 4 then
- local res = ccftp.changeUserPass(tArgs[2], tArgs[3], tArgs[4])
- if res == true then
- print("Password from User "..tArgs[2].." was changed")
- elseif res == "nsUsr" then
- printError("User by the name of "..tArgs[2].." does not exists!")
- elseif res == "pww" then
- printError("The entered password was wrong!")
- end
- else
- printError("Not enought Arguments!")
- end
- elseif string.lower(tArgs[1]) == "rmuser" then
- -- 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
- if #tArgs >= 3 then
- local res = ccftp.removeUser(tArgs[2], tArgs[3])
- if res == true then
- print("User by the name of "..tArgs[2].." was removed!")
- elseif res == "nsUsr" then
- printError("There is no User by the name of "..tArgs[2])
- elseif res == "pww" then
- printError("Ther entered password is wrong!")
- end
- else
- printError("Not enought Arguments!")
- end
- else
- -- gives the user the usage if insufficent arguments are given
- printError([[Usage:
- runserver 'hostname' (FTP-Share) -- Runs Server
- closeserver -- Shuts down any running ccFTP-Hosts
- cuser 'UserName' 'Password' -- creats new Account
- chguser 'oldUserName' 'newUserName' 'Password' -- renames a User
- passwd 'UserName' 'oldPassword' 'newPassword' -- changes a Password
- rmuser 'UserName' 'Password' -- removes a User]])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement