Daily report on server files

You can share your Lua Scripts with everybody here.

Daily report on server files

Postby chazjn » Wed Sep 24, 2014 12:27 pm

Hello all,

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

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)

--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.."/"
               fullPath = path..file
               if date == nil then
                  table.insert(fileTable, fullPath)
                  fileDate = GetFileDate(fullPath,dateFormat)
                  if fileDate == date then
                     table.insert(fileTable, fullPath)

   return fileTable

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"

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"

--now send the email
Wed Sep 24, 2014 11:30 am

Re: Daily report on server files

Postby FTP » Mon Sep 29, 2014 2:23 am

Thanks for your sharing, I think it will be helpful for somebody.
Site Admin
Tue Sep 29, 2009 6:09 am

Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 2 guests