Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS-DOS FTP command in a batch file: raise error

In MS-DOS (Windows 2003 R2 Server), I have a batchfile which has the FTP command in it, eg:-

FTP.CMD
-------
cd d:\extracts\scripts
ftp -i -s:ftp_getfile.ftp
exit

I would like the batch file to raise and return an error level 1 for failure instead of 0, so that the calling batchfile can deal with it.

The error could be caused by the FTP server being down. Right now, nothing is returned to indicate an error condition occured.

Please can someone advise?

Thanks! :)

like image 845
Learner74 Avatar asked Mar 04 '26 16:03

Learner74


1 Answers

Maybe too late, but it is possible. I'm running the following script to check for errors in the text that's returned by the FTP script. If you know the error text that's returned by FTP, then that's what you look for with the 'find' command. The ftp commands are in a file called ftp.inp, just check out the help of FTP on how to use '-s'.

ftp -s:ftp.inp > ftp.log

find /I /C "not connected" ftp.log
IF NOT ERRORLEVEL 1 GOTO FTPERROR

find /I /C "not found" ftp.log
IF NOT ERRORLEVEL 1 GOTO FTPERROR

find /I /C "failed" ftp.log
IF NOT ERRORLEVEL 1 GOTO FTPERROR

REM --- no errors found
GOTO :END

:FTPERROR
REM --- error found

:END
like image 76
Martijn S Avatar answered Mar 07 '26 14:03

Martijn S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!