2

I'm trying to send files through SFTP by using the below script but after 10 seconds the SFTP connection closed and some files did not send without getting any errors.

Script:

#!/bin/sh
HOST=xxx.xxx.xxx.xxx
USER=smsu
PASS=XXXXX

expect -c "
spawn sftp -oPort=22 ${USER}@${HOST}
expect \"password: \"
send \"${PASS}\r\"
expect \"sftp>\"
send \"lcd /home/suv/msu\r\"
send \"mput *.*\r\"
expect \"sftp>\"
send \"bye\r\"
expect \"#\"
"
2
  • 1
    First, I would not be coding passwords, use keys instead.
    – Bib
    Jul 25 at 12:04
  • Honestly why don't you create a key-pair, and then just scp *.* smsu@xxx.xxx.xxx.xxx:/home/suv/msu ...? Or even use rsync?
    – tink
    Jul 26 at 8:10
2

If it takes more than 10 seconds to transfer a file, it will timeout, as expect will think it has gone away.

You need something like, from the man page:

set timeout 30
1
  • It's working fine now, Many thanks. Jul 25 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.