Reputation: 143
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! :)
Upvotes: 3
Views: 13212
Reputation: 31
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
Upvotes: 3
Reputation: 2305
As per this question: How to capture the ftp error code in batch scripts?
The windows FTP command doesn't support this behaviour (or PASV mode) and is basically next to useless.
You might want to try NcFtp instead. It's free, small, portable, and has decent error codes.
Upvotes: 1