Post upload scripts - run python

Core FTP Server questions and answers
Post Reply
ash_aqx
Posts: 2
Joined: Thu Feb 04, 2021 4:09 am

Post upload scripts - run python

Post by ash_aqx »

Hi All,

Hoping you can help, tried searching the forum but all my search terms were too common.
I'm trying to run a python script on post upload. I've tried all the combinations that I can think of. Is there some way to debug or step through the command execution?

I've tried:
- "%ProgramFiles%\python313\python.exe" "c:\scripts\myscript.py" -c config.json -f %1 -p %2"
- cmd.exe /c "%ProgramFiles%\python313\python.exe" "c:\scripts\myscript.py" -c config.json -f %1 -p %2"

And just about every combination in between, the script does work from cmd or powershell, so I feel like i'm missing something obvious.

The error I get back in my ftp client varies between:
- 552 Transfer aborted. External call failed (External execute error - The system cannot find the file specified
- 552 Transfer aborted. External call failed (return code - 1)....
depending on how it's structured.

I was able to get curl to run using
- "c:\tools\curl.exe" --insecure --header "Content-Type:image/jpeg" --data-binary @%1 "https://mysite.com
but having no luck with python.

Hopefully you wonderful people have some tips!
Thanks
ForumAdmin
Site Admin
Posts: 988
Joined: Mon Mar 24, 2003 4:37 am

Re: Post upload scripts - run python

Post by ForumAdmin »

1) -c config.json (does this need a full path?)

2) Try the call without the cmd.exe /c portion.

3) echo %ProgramFiles% out to a file to verify the environment variable is accurate.

If none of these helps then this will be tested further.
ash_aqx
Posts: 2
Joined: Thu Feb 04, 2021 4:09 am

Re: Post upload scripts - run python

Post by ash_aqx »

Thanks for the quick response.
I used the following to check the env variable:
- cmd.exe /c "echo" %ProgramFiles% %1 %2 >> c:\scripts\error.txt

the contents looks correct:
- C:\Program Files c:\data\ftp\test_account\test.txt c:\data\ftp\test_account\

I then added redirection for errors on the end of the previous script
- >> c:\scripts\error.log 2>&1

And caught this:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Next step, I replaced the env variable with the string literal.. and everything started working.
My only guess is that for some reason using an env variable is escaping the quotes, I tried all types of escape character but no good.

This was the winning combination:
cmd.exe /c "C:\Program Files\Python313\python.exe" C:\path\to\script.py -c config.json -f %1 -p %2 >> c:\scripts\error.log 2>&1

Thanks for your help.
Post Reply