I want to find if a file exists at FTP using if-exist filename -else statement using FTP batch script which is as follows:
ftp.txt open ftp.mysite.com
ftp.txt us
Don't do the logic in the FTP script.
Call the ftp.txt script from a batch file. Within your ftp.txt script, just do a GET on your file. If the file is there, it'll be downloaded to the local directory. Otherwise, it won't. After calling the FTP script, check the file's existence in your local directory using standard DOS batch commands, i.e.:
@echo off
:FETCHFILE
ftp -s:ftp.txt
IF EXIST filetocheckfor.txt (
REM the file was there, so do something
) ELSE
echo Trying again...
REM ping "sleep" would go here
GOTO FETCHFILE
)
If you want to build a delay into your retries, perform a "sleep" by pinging a bogus IP address, as described in this post: http://www.dullsharpness.com/2010/06/14/elapsed-timer-using-pure-ms-dos/