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

12,946

Solution 1

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

Solution 2

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.

Share:
12,946
Learner74
Author by

Learner74

Updated on August 12, 2022

Comments

  • Learner74
    Learner74 over 1 year

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

  • Learner74
    Learner74 almost 12 years
    ok, seems the stock FTP on Windows just can't do it. I'll try NcFtp instead! Thanks!
  • Learner74
    Learner74 almost 12 years
    It doesn't seem to work in 64-bit Windows (Win 7 or Win 2003 R2). :-/
  • aboy021
    aboy021 almost 12 years
    I'm using NcFTP Client 3.2.5 for Microsoft Windows on Windows 7 x64 and Windows Server 2008 x64 with no issues.
  • Learner74
    Learner74 almost 11 years
    Thanks for the reply Martin, I eventually solved this by using a third-party FTP command-line client called WinSCP portable winscp.net/eng/download.php , this can raise several error codes upon exit.