title: Optimistic way to test port before executing sftp
body: <p>I have a bash script which is doing very plain sftp to transfer data to production and uat servers. See my code below.</p>
  
  <pre><code>  if [ `ls -1 ${inputPath}|wc -l` -gt 0 ]; then
          sh -x wipprod.sh &gt;&gt; ${sftpProdLog}
          sh -x wipdev.sh &gt;&gt; ${sftpDevLog}
          sh -x wipdevone.sh &gt;&gt; ${sftpDevoneLog}
    fi
  </code></pre>
  
  <p>sometimes the UAT server may go down. In those cases the number of scripts hanged are getting increased. If it reaches the user max. number of process the other scripts also getting affected. So I am thinking before executing each of the above script i have to test the port 22 availability on the destination server. Then I can execute the script. </p>
  
  <p>Is this the right way? If yes what is the optimistic way to do that? If no what else is the best approach to avoid unnecessary sftp connection when destination not available? Thanks in advance.</p>