Events for local file manipulation?

Please post here if you have problems in using Wing FTP Server.
Post Reply
jvalent
Posts: 5
Joined: Sat Apr 02, 2016 3:58 pm

Events for local file manipulation?

Post by jvalent »

Hi, it is possible create event if file is uploaded to folder localy?

Thank you
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Events for local file manipulation?

Post by FTP »

What do you want? You can send email or execute the Lua script in the event "OnFileUploaded".
jvalent
Posts: 5
Joined: Sat Apr 02, 2016 3:58 pm

Re: Events for local file manipulation?

Post by jvalent »

I know, but this working only if file uploaded over FTP, HTTP or SSH. I need execute Lua script if file is copied to folder normally in windows.

Thank you and Sorry for my bad English, using Google translator.
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Events for local file manipulation?

Post by FTP »

OK, maybe you need a local file monitor software, just google it.
jvalent
Posts: 5
Joined: Sat Apr 02, 2016 3:58 pm

Re: Events for local file manipulation?

Post by jvalent »

Solved by hourly event and this LUA script.

Code: Select all

local movies = "D:/Movies/"
local emailSubject = "New files"
local emailBody = ""
local emailSMTP = "MySMTP"

function difference(a, b)
    local aa = {}
    for k,v in pairs(a) do aa[v]=true end
    for k,v in pairs(b) do aa[v]=nil end
    local ret = ""
    local n = 0
    for k,v in pairs(a) do
        if aa[v] then
			v = string.gsub(v,movies,"")
			n=n+1
			ret = ret..v.."\n"
		end
    end
    return ret
end

function FileWalker(options)
	local oldlist = {}
	local newlist = ""
	local path = options.path
	local fileTable = {}
	for line in io.lines(options.old) do
		table.insert(oldlist, line)
	end
	function walk(path)
		for isdir, file in c_GetFileDir(path) do
			if isdir == true then
				fullPath = path..file.."/"
				walk(fullPath)
            else
				fullPath = path..file
				table.insert(fileTable, fullPath)
				newlist = newlist..fullPath.."\n"
            end
		end
	end
	walk(path)
	local file = io.open(options.old, "w")
	file:write(newlist)
	file:close()
	return difference(fileTable,oldlist)
end

local updates = FileWalker{path=movies, old="D:/movies.txt"}


if updates ~= "" then
	emailBody = emailBody.."New movies on FTP: \n\n"..updates.."\n\n"
end

if emailBody ~= "" then
	c_SendMail("your@domain.com",emailSubject,emailBody,"",emailSMTP)
end
Post Reply