problem with %PathName, %FileName in LUA

Please post here if you have problems in using Wing FTP Server.

problem with %PathName, %FileName in LUA

Postby JohnsonCat » Mon Nov 30, 2020 2:18 am

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
 
10
 
Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Postby JohnsonCat » Mon Nov 30, 2020 3:48 am

or maybe there's a length limit of %PathName can return?
JohnsonCat
 
10
 
Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Postby FTP » Mon Nov 30, 2020 3:44 pm

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

Re: problem with %PathName, %FileName in LUA

Postby JohnsonCat » Mon Nov 30, 2020 11:16 pm

that was just not pasted from the code.
JohnsonCat
 
10
 
Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Postby FTP » Tue Dec 01, 2020 5:21 am

OK, so I think the error was caused by the code after "then", please check it.
FTP
Site Admin
 
1782
 
Tue Sep 29, 2009 6:09 am

Re: problem with %PathName, %FileName in LUA

Postby JohnsonCat » Wed Dec 02, 2020 2:01 am

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
JohnsonCat
 
10
 
Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Postby FTP » Wed Dec 02, 2020 3:18 pm

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

Re: problem with %PathName, %FileName in LUA

Postby JohnsonCat » Tue Dec 08, 2020 3:44 am

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
 
10
 
Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Postby JohnsonCat » Tue Dec 08, 2020 5:39 am

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")
JohnsonCat
 
10
 
Mon Nov 02, 2020 5:58 am

Re: problem with %PathName, %FileName in LUA

Postby FTP » Tue Dec 08, 2020 4:58 pm

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/20535/string-find--introduction
FTP
Site Admin
 
1782
 
Tue Sep 29, 2009 6:09 am


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests