Pull all users alongside their last login?

You can share your Lua Scripts with everybody here.

Pull all users alongside their last login?

Postby AdrianK » Tue Sep 21, 2021 1:14 pm

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?
AdrianK
 
3
 
Tue Sep 21, 2021 1:10 pm

Re: Pull all users alongside their last login?

Postby FTP » Tue Sep 21, 2021 3:50 pm

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
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Re: Pull all users alongside their last login?

Postby AdrianK » Wed Sep 22, 2021 8:36 am

Thanks for that!

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

Re: Pull all users alongside their last login?

Postby AdrianK » Sat Nov 06, 2021 8:54 pm

Help! :)
AdrianK
 
3
 
Tue Sep 21, 2021 1:10 pm


Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron