A.K
A.K

Reputation: 98

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 /test\r"
expect "sftp>"
send "mkdir XML\r"
expect "sftp>"
send "cd /test/XML\r"
expect "sftp>"
send "mput *\r"
expect "sftp>"
send "bye\r"
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.

Upvotes: 1

Views: 2459

Answers (1)

A.K
A.K

Reputation: 98

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 /test\r"
expect "sftp>"
send "mkdir XML\r"
expect "sftp>"
send "cd /test/XML\r"
expect "sftp>"
send "mput *\r"
expect "sftp>"
send "bye\r"
EOF

Upvotes: 1

Related Questions