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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Couldn't read packet: Connection reset by peer send: spawn id exp4 not open while executing
# 1  
Old 12-19-2018
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.


Code:
#!/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

Code:
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...


Last edited by Corona688; 12-19-2018 at 05:29 PM.. Reason: Code tags for code please
# 2  
Old 12-19-2018
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?
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Can't SSH - Connection reset by Peer

Hi Guys, I can't SSH to a remote system - connection reset by peer..any ideas ? -The Source is Linux, the Remote is Windows -The remote has OpenSSH running on Port 22 - Telnet confirms port is open -User1 has a RSA2 Key (2048) key, which is capture in the 1010101-pub.key specified by the... (1 Reply)
Discussion started by: stevie_velvet
1 Replies

2. Shell Programming and Scripting

Expect script error : send: spawn id exp4 not open

Hi, I am executing a expect script in while loop for doing telnet on list of servers stored in file as below : expect script : #!/usr/bin/expect -f set timeout 20 set ip set port if { == 0} { send_user "Usage: scriptname ip port\n" exit 1 } #exp_internal 1 log_user 0 spawn... (3 Replies)
Discussion started by: omkar.jadhav
3 Replies

3. UNIX for Dummies Questions & Answers

Sftp - Couldn't read packet: Connection reset by peer

Hello to all, i have a problem when trying to estabilish a sftp connection. i setup a sftp server (i used feeFTPd) and i'm now trying to connect from two different machines. from the first one everything is fine: $ sftp -vvv user@xxx.xxx.xxx.xxx Connecting to xxx.xxx.xxx.xxx...... (9 Replies)
Discussion started by: dc26
9 Replies

4. UNIX for Advanced & Expert Users

Fatal: Read from socket failed: Connection reset by peer [preauth]

Hello, I have recently updated my AIX machine from version 6.1.7.5 to 6.1.9.1 and i noticed that the errpt of the server is full of ssh messages like the one below: sshdprocess_id>]: fatal: Read from socket failed: Connection reset by peer Does anyone knows if this a known bug of the ssh... (15 Replies)
Discussion started by: omonoiatis9
15 Replies

5. UNIX for Dummies Questions & Answers

fatal: Read from socket failed: Connection reset by peer

I get this error when I log in through console: "fatal: Read from socket failed: Connection reset by peer". Can you tell me what this is and why it happens, and how to stop it? Thank you. (1 Reply)
Discussion started by: iamnew2solaris
1 Replies

6. UNIX for Advanced & Expert Users

Connection reset by peer..closing connection

Hello I'm facing the above problem while doing a performance run. I've a script which I'm launching from my windows desktop using mozilla. The script will invoke backend action on a Solaris host which in turn feeds the records to a driver located on a linux box(Cent OS). What's happening is... (1 Reply)
Discussion started by: subramanyab
1 Replies

7. IP Networking

connection reset by peer on freebsd

hi all. am running postgresql in a vm on debian server. i have some client programs connecting to the db. when i check the logs of postgresql i see "connection reset by peer" can someone help me with this issue... thanks. (1 Reply)
Discussion started by: coolatt
1 Replies

8. Shell Programming and Scripting

Connection reset by peer

hi i am connecting to a remote server using sftp protocol. i am using the command like "sftp USER01@122.10.12.45" then i got the error "Couldn't read packet: Connection reset by peer" please help its very urgent (5 Replies)
Discussion started by: Satyak
5 Replies

9. Shell Programming and Scripting

ssh - connection reset by peer

I use ssh to work on the server (OS X 10.4.x) remotely from home (Debian / OS X 10.5.3). If I leave my machine idle, I get disconnected after a couple of minutes. I get the following error message: Read from remote host "server name": Connection reset by peer Connection to "server name" closed.... (2 Replies)
Discussion started by: osxhawk
2 Replies

10. IP Networking

connection reset by peer

:confused: HI, We have 2 servers ( win 2003 + sun 5.8 ) and we run a rsh from the NT to the UNIX. The program runs a shell script on the UNIX and waits for the answer in the EOF. How ever, after period of appx 2 min there is a reply "Recv failed:Connection reset by peer". while the... (5 Replies)
Discussion started by: eyalush
5 Replies
Login or Register to Ask a Question