I am using mget command to FTP the .txt files from one server to another. It has been working fine for a year but for last few weeks it misses file sometimes. e.g yesterday 74 files were put on the server and we downloaded only 24 and session was closed. I am not able to figure out the exact reason causing this issue. Part of the code is below. Thank you.
cd $INCOMING_DIR
expect -c "
spawn sftp $RUSER@$RHOST
expect \"password\"
send \"$RPAWD\r\"
expect \"cd\"
send \"cd $RDIR\r\"
expect \"mget\"
send \"mget *.txt\r\"
expect \"bye\"
send \"bye\r\"
interact "
retcode=`echo $?`
if [ $retcode -eq 0 ]
then
FCOUNT=`ls *.txt 2>/dev/null|wc -l`
if [ $FCOUNT -gt 0 ]
then
echo "Got invoice files successfully."
echo "Removing the files from remote directory."
expect -c "
spawn sftp $RUSER@$RHOST
expect \"password\"
send \"$RPAWD\r\"
expect \"cd\"
send \"cd $RDIR\r\"
expect \"rm\"
send \"rm *.txt\r\"
expect \"bye\"
send \"bye\r\"
interact "
else
echo "There are no data files."
fi