Batch script to wait for file to be generated on FTP server and download
With this edit you can launch the batch file with the file name on the command line, like this:
ftpscript.bat "filename.ext"
Note that your lcd uses c:\
which is a restricted location in later versions of windows.
@echo off
>file.tmp echo open 10.100.16.111
>>file.tmp echo username
>>file.tmp echo password
>>file.tmp echo lcd c:\
>>file.tmp echo cd root/output_folder
>>file.tmp echo binary
>>file.tmp echo mget "%~1"
>>file.tmp echo disconnect
>>file.tmp echo bye
:retry
ftp -i -s:"file.tmp"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
del file.tmp
pause
Sabari Ram
An engineer, Software tester, part time script developer. Interested in batch scripts, vbs, JSP web page designing and Unix shell scripts. I strongly believe that 'Nothing is Impossible'
Updated on June 04, 2022Comments
-
Sabari Ram almost 2 years
I have a program in my FTP server to generate a file, which may take 3-5 minutes to complete and also I knew the name of the file which i being created by my program. Now, once I initiate the program in my server, I have keep checking until the file is created. Once it is created, I am using the below batch script to ftp the file to my local desktop.
@ftp -i -s:"%~f0"&GOTO:EOF open 10.100.16.111 username password lcd c:\ cd root/output_folder binary mget "*partial_file_name*" REM mget using wildcard search disconnect bye
This script works fine for me. But the problem is, I need modify this script as such, script should keep running until the file is generated. Because i don't know when the file creation will get completed. So, it will great if some one help/guide me to make a looping script which will wait until the completion of file creation and download the same file through FTP.