0

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 
oguz ismail
  • 1
  • 16
  • 47
  • 69
Chints
  • 1
  • 1
    Why do you use expect at all? Just `sftp .... -e 'cd $RDIR; rm *.txt'`? – KamilCuk Nov 22 '19 at 18:24
  • Have your sysadmin check any appropriate logs. `(s)ftp` servers can be configured to only allow a connection for X amount of time, so maybe that has changed on your system OR the files are much bigger OR something is causing a "pause" while reading the files and thus tripping a timeout. Agree that `-e` is appropriate option for `sftp` but I'd be surprised if `expect` is the cause of your `mget` problem. Good luck. – shellter Nov 22 '19 at 21:55

0 Answers0