简体   繁体   中英

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! :)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM