Couldn't read packet: Connection reset by peer send: spawn id exp4 not open while executing

Hi All, I am having an issue with my script which I am using to get files from a remote server.

In my script I am going to server:- REMOTESERVER and directory:- /Interface/Upload, and then getting files from there to my local server directory:- /ftp/jail_nextview_LMS/home/nextview_LMS/outbox.

Could you please look at my script file once and the error log and help me to understand why this error is coming, it will be a great help, thank you very much.

#!/bin/sh
HOST='REMOTESERVER'
USER='usrnameftp'
PASSWD='password123'
PORT=22
KEY_AUTH_FILE=''
GET_LOCAL_DIR='/Interface/Upload'
GET_REMOTE_DIR='/ftp/jail_nextview_LMS/home/nextview_LMS/outbox'
GET_REMOTE_DIR_ARCH='/ftp/jail_nextview_LMS/home/nextview_LMS/outbox/processed'
GET_LS_CRETERIA='NextView*.csv'
GET_RENAME_LOG='/ftp/justin/inbox/xml/logs'
export PATH=$PATH:/bin:/usr/local/bin:/usr/bin

#GET FILES
echo "get files "
cd $GET_REMOTE_DIR
echo "get local directory: $GET_REMOTE_DIR"
echo "path is: $PATH"

echo "opening sftp for get files"
set timeout 30
/usr/bin/expect<<EOD
spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST
expect "password:"
send "$PASSWD\r"
expect "sftp>"
send "pwd\r"
expect "sftp>"
send "cd $GET_LOCAL_DIR\r"
expect "sftp>"
send "lcd $GET_REMOTE_DIR\r"
expect "sftp>"
send "mget $GET_LS_CRETERIA\r"
set timeout 200
expect "sftp>"
send "bye\r"
EOD

echo "Checking log file..."$LOG_GET_GENNINV_FILE
LOGIN_FAIL_MSG='530 Login incorrect.'
if fgrep "$LOGIN_FAIL_MSG" $LOG_GET_GENNINV_FILE ;
then
/home/mqsiuid9/InterfaceSFTP/shellscripts/helpdeskalert $0    
	echo "Error in SFTP" 
    exit 1
else    
	echo "sftp Success" 
fi 

echo "Achiving  files in remote host: "
export DATENOW=$(date +%Y%m%d%H%M%S)
echo "datenow is: $DATENOW"
echo "Renaming below files in remote host: "
echo "$(ls)"
find $GET_REMOTE_DIR -maxdepth 1 -empty -type f -exec rm {} \;
for FILES in $(ls)
do
echo "renaming file at remote host: $FILES"
/usr/bin/expect<<EOD1
spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST
expect "password:"
send "$PASSWD\r"
expect "sftp>"
send "pwd\r"
expect "sftp>"
send "cd $GET_LOCAL_DIR\r"
expect "sftp>"
send "lcd $GET_REMOTE_DIR\r"
expect "sftp>"
send "rename ${GET_LOCAL_DIR}/${FILES}.${DATENOW}\r"
expect "sftp>"
send "bye\r"
EOD1
done
	#sleep 60
	echo "moving to inbox folder in local"
		echo "SFTP success and renaming local file!!!!"		
		mv $FILES ${GET_REMOTE_DIR}/${FILES}.ready
done

exit 0
ERROR LOG:- 
path is: /usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/puppetlabs/bin:.:/home/mqsiuid9/scripts:/home/mqsiuid9/bin:/usr/local/apache2/bin:/bin:/usr/local/bin:/usr/bin
opening sftp for get files
spawn /usr/bin/sftp -o Port=22 jstediftp@REMOTESERVER
Connecting to REMOTESERVER...
password123
pwd
cd /Interface/Upload
lcd /ftp/jail_nextview_LMS/home/nextview_LMS/outbox
mget NextView*.csv
ssh: connect to host REMOTESERVER port 22: Connection timed out
Couldn't read packet: Connection reset by peer
send: spawn id exp4 not open
 while executing
"send "bye\r""
Checking log file...

It's telling you that it couldn't connect to REMOTESERVER, because the connection timed out. Unless you got the hostname wrong or something, not something you can correct on your end.

Why are you using a brute-forcing tool to inject plaintext passwords into sftp when you can save yourself a lot of complication and trouble and use keys?

1 Like