title: Catching errors in SCP or SFTP
body: <p>I am writing a script that will transfer a file from one server to another using SCP or SFTP.  It is very important for me to differentiate between different types of errors that occur.</p>
  
  <p>My problem, is that the error code returned from SFTP and (especially) SCP does not seem to distinguish between different types of errors.</p>
  
  <p>For example, when SCP-ing, it seems as if I get an error code of 1, no matter what type of error is actually occurring (ex: perrmission denied, could not connect to host both return error code 1).  </p>
  
  <p>For SFTP or SCP, is there a way to reliably determine an error that is occurring; without having to parse through $stderr and extract the error that way? </p>