ftp error and errorlevel

October 1, 2012 at 06:25:24
Specs: Windows Server 2003

How I can catch an ftp error with the errorlevel in an batch-file.
I try it in this way:

ftp -n -s:ftp.conf

if %errorlevel%==0 goto ok
else goto error

echo filetransfer is ok
goto eof

echo error in filetransfer
goto eof


But the errorlevel is 0 if the filetransfer was succesfull and it is 0 if the filetransfer was not successfull. What is my mistake.

Greetings georg.

See More: ftp error and errorlevel

Report •

October 1, 2012 at 13:09:52
I've never tried this with FTP but it may work:

ftp -n -s:ftp.conf || echo error in file transfer


Report •

October 1, 2012 at 17:36:59
I don't think you can use errorlevel from ftp directly. If that is the case, you will have to redirect or pipe the output of ftp, then use "find" to analyze it. The searchstring will vary depending on what ftp command you want to verify. f/e: if "get", the error will be "550 no such file or directory", but if "put", the error might be "file not found" (if that is indeed the cause of the error - there are other possiblities such as the file being inaccessible (opened/in use etc). then your command would look like this:
ftp -n -s:ftp.conf | find /i "no such file" && goto :fail || goto :success

Of course, errorlevel is now opposite polarity from the usual: zero means "problem/error" and not-zero means "ok" (because "find" is looking for error message, and if found, then "problem") There is no "general purpose" failure with ftp because there are about 35 or 40 different functions each of which will generate a different error-message on failure. That all depends on the content of your ftp script "ftp.conf".

Report •

Related Solutions

Ask Question