I need to create a batch file that goes to a protected FTP site, checks if a file type (*.txt
) exists, and if it does, proceed to the next step, if not, return a 0 and end the job.
I've done extensive searching and couldn't find any solutions.
I need to create a batch file that goes to a protected FTP site, checks if a file type (*.txt
) exists, and if it does, proceed to the next step, if not, return a 0 and end the job.
I've done extensive searching and couldn't find any solutions.
It's not a trivial task, particularly if you need to check for a file matching a mask (not for a specific file).
You can use WinSCP scripting:
@echo off
set REMOTE_PATH=/home/user/*.txt
winscp.com /command ^
"open ftp://user:password@host/" ^
"option failonnomatch on" ^
"ls %REMOTE_PATH%" ^
"exit"
if %ERRORLEVEL% neq 0 goto error
echo File(s) matching %REMOTE_PATH% exist
rem Do something
exit 0
:error
echo Error or no file matching %REMOTE_PATH% exists
exit 1
The above code is from the WinSCP article on Checking file existence.
(I'm the author of WinSCP)