PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Jun 25, 2017 5:36 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Bash / Expect Script
PostPosted: Tue Apr 26, 2011 10:31 am 
Offline
Forum Newbie
User avatar

Joined: Thu Apr 21, 2011 2:56 pm
Posts: 18
Location: Murray, UT
Hey everyone, I'm currently working on a Bash / Expect script that will sftp to a server, pull down some .txt files, run some commands, and then exit. Right now I'm actually having problems with the Expect piece of the script.

It all works fine until I run the mget command. For some reason it only gets the first file, and then part of the second. I'm not sure why this happens and haven't found much on my own in the Expect Man Page. http://www.tcl.tk/man/expect5.31/expect.1.html.

Here's my expect script thus far:
Syntax: [ Download ] [ Hide ]
#!/usr/bin/expect
spawn sftp user@someserver.com
expect "Password:"
send "Some_Pass\n";
expect "sftp>"
send "cd fromcheetah\n"
expect "sftp>"
send "mget *\n"
expect "sftp>"
send "exit"
 



Any suggestions on how I can make sure that I get ALL the files before expect exits?


UPDATE:
Finally found the solution. In passing the Expect Man Page says that the default timeout for "expect" is 10 seconds. I just had to set that to a longer time so that it would wait for the file transfer to finish. The correct script is below:
Syntax: [ Download ] [ Hide ]
#!/usr/bin/expect
spawn sftp user@someserver.com
expect "Password:"
send "Some_Pass\n";
expect "sftp>"
send "cd fromcheetah\n"
expect "sftp>"
send "mget *\n"
set timeout 10000
expect "sftp>"
send "exit"
 


Top
 Profile  
 
 Post subject: Re: Bash / Expect Script
PostPosted: Tue Apr 26, 2011 2:15 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5975
Location: Odessa, Ukraine
Wouldn't scp + public key auth be a simpler solution?


Top
 Profile  
 
 Post subject: Re: Bash / Expect Script
PostPosted: Thu Jun 30, 2016 10:09 am 
Offline
Forum Newbie

Joined: Thu Jun 30, 2016 10:04 am
Posts: 1
Thank you for posting this. Couldn't figure out why my ftp script was dying after transferring a number of files. You're a lifesaver.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group