Skip to content
Advertisement

Unable to mput all the files through sftp in the remote server using expect

I’m trying to mput all files present in the directory : /Test/XML/ into a remote sftp server with the help of expect utility.

I’ve around 320 files in the directory: /Test/XML/.

The size of each file is around 0.1 MB.

There’s no error observed.

Here’s my code:

cd /Test/XML/

/usr/bin/expect <<EOF
spawn /usr/bin/sftp ${user_name}@${HOSTNAME}
expect "password:"
send "${passwd}r"
expect "sftp>"
send "cd /testr"
expect "sftp>"
send "mkdir XMLr"
expect "sftp>"
send "cd /test/XMLr"
expect "sftp>"
send "mput *r"
expect "sftp>"
send "byer"
EOF 

But the problem here is, mput * is transferring only 4 files instead of transferring all the 320 files. Not sure, why it’s not able to transfer all the 320 files in the remote server.

Any help is most welcome.

Advertisement

Answer

Thanks @ThiruShetty for the hint of using set timeout -1 in the expect utility.

Actually, i had a lot of files(~320-350) to be transferred(sftp) to a remote server. With the normal execution of sftp using expect utility, it was able to transfer only a few files, not all of them which i wanted.

After inserting set timeout -1 inside expect, it solved the problem of timeout.

Here’s the final code:

cd /Test/XML/

/usr/bin/expect <<EOF
set timeout -1
spawn /usr/bin/sftp ${user_name}@${HOSTNAME}
expect "password:"
send "${passwd}r"
expect "sftp>"
send "cd /testr"
expect "sftp>"
send "mkdir XMLr"
expect "sftp>"
send "cd /test/XMLr"
expect "sftp>"
send "mput *r"
expect "sftp>"
send "byer"
EOF
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement