problem with %PathName, %FileName in LUA

Please post here if you have problems in using Wing FTP Server.
Post Reply
JohnsonCat
Posts: 10
Joined: Mon Nov 02, 2020 5:58 am

problem with %PathName, %FileName in LUA

Post by JohnsonCat »

i just noticed our LUA script not always works.
the script is

if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
en

for example, when the file is D://WFTP/Data/GCT/3. Booking token applied/a) Customer sample with booking ticket/Gold Class Hopper BRT Token 27-11-2020.xlsx, i can see an error 'Failed to execute lua script of event'

i initially though that was because of '-', but other files with '-' seem to be fine when in other folders.
An ideas?
JohnsonCat
Posts: 10
Joined: Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Post by JohnsonCat »

or maybe there's a length limit of %PathName can return?
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: problem with %PathName, %FileName in LUA

Post by FTP »

I just tested with your script in the event "OnFileUploaded", everything is OK. Is it because that you missed a character "d" in the end? It should be:

Code: Select all

if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
...
end
JohnsonCat
Posts: 10
Joined: Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Post by JohnsonCat »

that was just not pasted from the code.
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: problem with %PathName, %FileName in LUA

Post by FTP »

OK, so I think the error was caused by the code after "then", please check it.
JohnsonCat
Posts: 10
Joined: Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Post by JohnsonCat »

after massive tests i think it's string.find and string.match don't like ')' in the strings.
for example:
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
end

this is fine, but
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a) customer sample with booking ticket/') then
do something
end

this is not working, as long as ')' is in the string, any idea to bypass that? thanks
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: problem with %PathName, %FileName in LUA

Post by FTP »

OK, because some special characters like "( ) . % + - * ? [ ^ $" called magic characters in Lua language, you need to add a "%" before the magic character.

Code: Select all

if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a%) customer sample with booking ticket/') then
...
end
JohnsonCat
Posts: 10
Joined: Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Post by JohnsonCat »

lua is quite hard to understand...
if i get a path from %PathName, which contains special symbol like '()', how do I replace it before parse it to string.find or string.match function?
in other programming language, usually it's quite easy to force convert to string or other types...
Thank you.
JohnsonCat
Posts: 10
Joined: Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Post by JohnsonCat »

the function i wrote:

function email(p1,p2,f,e)
if string.find(string.lower(p1), string.lower(p2)) then
c_SendMail(e,f.." is uploaded","File path is ["..p2..string.match(string.lower(p1), string.lower(p2)..'(.*)').."]","","SMTP")
end
end

email('%PathName','/path/','%FileName',"somebody@domain.com")
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: problem with %PathName, %FileName in LUA

Post by FTP »

OK, only the 2nd parameter of the function "string.find" needs to handle magic characters, please have a look at this document: https://riptutorial.com/lua/example/205 ... troduction" rel="nofollow
Post Reply