I am trying to check the existing directory on a remote server. I am using the below code to check that but somehow It doesn't seem working correctly. your help will be much appreciated.
sftp -o "IdentityFile=${sftpkey}" ${sftpaccount}@${sftphost} [:dir [$pocOutbound]] <<EOF >/dev/null 2>&1
cd "${pocOutbound}"
bye
EOF
if [ $? -ne 0 ]
then
logmsg "folder does not exist"
exit 2
fi