This is my daily report on server files. I run it at midnight to get the list of files that have been modified the day before plus a list of ALL files that are on the server. Please let me know what you think.
nb. if you want to test the report without emailing then use print to view instead:
Code: Select all
print(emailBody)
Code: Select all
local root_dir = "D:/WingFTPRoot/CLIENTS/"
local dateFormat = "%d/%m/%Y"
local today = os.date(dateFormat)
local yesterday = os.date(dateFormat,os.time()-24*60*60)
local emailTo = "test@example.com"
local emailSubject = "WingFTP Report for "..today
local emailBody = ""
local emailSMTP = "YourSMTPConfig"
--this function returns the date of the file in the specified format
function GetFileDate(file, dateFormat)
local fileDate = c_GetFileTime(file)
return os.date(dateFormat, fileDate)
end
--this function walks the folder structure and returns a table of files found
--optionally can specify a date filter to return only files modified on that date
function FileWalker(options)
local path = options.path
local date = options.date or nil
local fileTable = {}
function walk(path)
for isdir, file in c_GetFileDir(path) do
if isdir == true then
fullPath = path..file.."/"
walk(fullPath)
else
fullPath = path..file
if date == nil then
table.insert(fileTable, fullPath)
else
fileDate = GetFileDate(fullPath,dateFormat)
if fileDate == date then
table.insert(fileTable, fullPath)
end
end
end
end
end
walk(path)
return fileTable
end
local newFiles = FileWalker{path=root_dir, date=yesterday}
local allFiles = FileWalker{path=root_dir}
--this part builds the email body
emailBody = "WingFTP server report for "..today.."\n\n"
emailBody = emailBody.."Files uploaded yesterday: "..(#(newFiles)).."\n"
for k, v in pairs(newFiles) do
v = string.gsub(v,root_dir,"")
emailBody = emailBody..k.." : "..v.."\n"
end
emailBody = emailBody.."\n\n"
emailBody = emailBody.."All files on server: "..(#(allFiles)).."\n"
for k, v in pairs(allFiles) do
v = string.gsub(v,root_dir,"")
emailBody = emailBody..k.." : "..v.."\n"
end
--now send the email
c_SendMail(emailTo,emailSubject,emailBody,"",emailSMTP)