Sftp hanging

Hi All,

I am transfering a file through sftp. But the script is hanging at exit occasionally.

I am suspecting that sftp is hanging due to buffer size issue.

If that is the case can any body suggest a solution.

Please find the code.

 
echo "cd /${CUST_ID}/inbound/${SAFET_ID}" > $BATCHFILE
echo "put ${SOURCE_FILE} ${FILE_NAME}" >> $BATCHFILE
echo "exit" >> $BATCHFILE
cmd="sftp -o port=2022 -b $BATCHFILE user@$SERVER"
$cmd >> $LOGFILE 2>&1
if [ $ret -ne 0 ] 2>>$LOGFILE
then
echo "Failure" >> $LOGFILE
else
echo "Success">> $LOGFILE
fi