Pull all users alongside their last login?

You can share your Lua Scripts with everybody here.
Post Reply
AdrianK
Posts: 4
Joined: Tue Sep 21, 2021 1:10 pm

Pull all users alongside their last login?

Post by AdrianK »

This is the script I am trying to use:

Code: Select all

do
local strDomain = "ftp.xxxxxx.org.uk"
local strUserlist = c_GetUserList(strDomain)
local userlist = Split(strUserlist,"\n")

local strResult = ""
for _,username in pairs(userlist) do
local user = c_GetUser(strDomain,username)
strResult = strResult..strDomain.."\t"..username.."\t"..user.last_logintime.."\t"..user.expiretime.."\n"
end

local fp = assert(io.open("c:/support/users.txt", "wb"))
fp:write(strResult)
fp:close()
end
Running using:

Code: Select all

"C:\Program Files (x86)\Wing FTP Server\wftpconsole.exe" -u ftpadmin -p xxxx -f C:\Support\Users_Pull.lua
but the script is not working as expected i.e. it bombs out on:

Code: Select all

some error in [string "do..."]:8: attempt to index local 'user' (a nil value)!
Does anyone have a working script or can fix the one above?
FTP
Site Admin
Posts: 1917
Joined: Tue Sep 29, 2009 6:09 am

Re: Pull all users alongside their last login?

Post by FTP »

OK, maybe you can try the following code:

Code: Select all

for _,username in pairs(userlist) do
local user = c_GetUser(strDomain,username)
    if user ~= nil then
        strResult = strResult..strDomain.."\t"..username.."\t"..user.last_logintime.."\t"..user.expiretime.."\n"
    end
end
AdrianK
Posts: 4
Joined: Tue Sep 21, 2021 1:10 pm

Re: Pull all users alongside their last login?

Post by AdrianK »

Thanks for that!

The script now runs properly without errors but produces blank output i.e. the text file has no data?
AdrianK
Posts: 4
Joined: Tue Sep 21, 2021 1:10 pm

Re: Pull all users alongside their last login?

Post by AdrianK »

Help! :)
AdrianK
Posts: 4
Joined: Tue Sep 21, 2021 1:10 pm

Re: Pull all users alongside their last login?

Post by AdrianK »

Help! :)
Post Reply