title: How to capture the ftp error code in batch scripts?
body: <p>I have a somewhat related, but different questions <a href="https://stackoverflow.com/questions/7158189/batch-file-not-accepting-parameter-in-the-form-of-1-2">here</a>. </p>
  
  <p>I have a batch script (<code>*.bat</code> file) such as this:</p>
  
  <pre><code>@ftp -i -s:"%~f0"&amp;GOTO:EOF
  open ftp.myhost.com
  myuser
  mypassword
  !:--- FTP commands below here ---
  lcd "C:\myfolder"
  cd  /testdir
  binary
  put "myfile.zip"
  disconnect
  bye
  </code></pre>
  
  <p>Basically this is a script that uploads a zip file to a ftp site. My question is that, the upload operation can fail from time to time ( the remote ftp is not available, "myfile.zip" is non-existent, upload operation interrupted and whatnot), and when such unfortunate things happen, I want my bat file return 1 ( <code>exit 1</code>).</p>
  
  <p>It would be great if my upload wasn't successful, the ftp would throw an exception ( yes, like exception in C++), and I would have a catch-all exception that catches it and then <code>exit 1</code>, but I don' think this is available in batch script.</p>
  
  <p>What is the best way to do what I need here?</p>