title: sftp return code
body: <p>I seacrhed the site for this problem but could not  find solution.Problem is related to sftp.I am running a script which accepets 7 parameters,does SSH and uploads the file on sftp server.Parameters i supply are-server,user,port,source_directory,target_directory,source_file and tager_file.
  if everything goes fine, file is uploaded without any error and return code is 0.
  Problem is if any parameter is wrong, like target_directory, even then script returns 0 as return value.Here is how script looks-</p>
  
  <pre><code>   typeset targetUsername=$1
  
  typeset targetHostname=$2
  
  typeset sftpPort=$3
  
  typeset sourceDir=$4
  
  typeset targetDir=$5
  
  typeset sourceFilename=$6
  
  typeset targetFilename=$7
  
  typeset cmdPut="put ${sourceDir}/${sourceFilename} ${targetTempDir}/${tmpFileNam
  e}"
  
  typeset cmdRen="rename ${targetTempDir}/${tmpFileName} ${targetDir}/${targetFile
  name}"
  
  sftp ${sftpOption} ${targetUsername}@${targetHostname} &lt;&lt;EOF
  
  ${cmdPut}
  
  ${cmdRen}
  
  bye
  EOF
  
  sftpStatus=$?
  </code></pre>
  
  <p>sftpStatus is supposed to return the status.But i am getting status as 0 always.
  Any idea, how to resove this?
  Thanks alot in advance.</p>