The Windows ftp.exe
always returns 0, no matter what.
All you can possibly do, is to parse its output and look for errors. But that's pretty unreliable.
If you want to take this approach anyway, see
Though, you better use some better FTP client. Sooner or later you will run into troubles with the ftp.exe
anyway, as it does not support an encryption, the passive mode or recursive transfers, among many other limitations.
If you are familiar with PowerShell, use the FtpWebRequest
or WebClient
from a Powershell script. There are numerous examples here, for example Upload files with FTP using PowerShell.
If not, use some 3rd party command-line FTP client.
For example with WinSCP FTP client, your batch file may look like:
@echo off
winscp.com /ini=nul /log=script.log /command ^
"open ftp://USERNAME:PASSWORD@ftp.example.com/" ^
"put C:\LOCAL\FILE /REMOTE/PATH/" ^
"exit"
if ERRORLEVEL 1 (
winscp.com /ini=nul /log=script2.log /command ^
"open ftp://USERNAME:DIFFERENTPASSWORD@ftp.example.com/" ^
"put C:\LOCAL\FILE /REMOTE/PATH/" ^
"exit"
)
References:
WinSCP can also be used from PowerShell, if you want even more robust implementation.
(I'm the author of WinSCP)