Operating System - HP-UX
1830235 Members
2465 Online
109999 Solutions
New Discussion

Expect script - ftp problem

 
SOLVED
Go to solution
Nick D'Angelo
Super Advisor

Expect script - ftp problem

HPUX 11i - I am using for a couple of automated processes of sending files out via ftp to outside sites.

One of them works without a problem, however, the second one seems to stop at the Password prompt.

I generated the expect script also for the problematic script using autoexpect.

I have attached my script.txt file.

Any suggestions?
Always learning
7 REPLIES 7
Amit Agarwal_1
Trusted Contributor

Re: Expect script - ftp problem

The autoexpect scripts shows

[snipped]
expect -exact "\r
331-Connected to destsite.r
331-welcome to destsite access restrictions apply. Time = 07:45:30\r
331 Password required for userid.\r
[snipped]

After entering the userid, the script expects the above output (you can notice the use of 'exact' keyword). But since the time is dynamic, it does not matches with '07:45:30' everytime you run it. Moreover the timeout has been set to infinite, hence it hangs.

You need to change the autoexpect script to allow flexible output from ftp. Replace the above lines with the below line and try.

expect "Password:"

You can also set the timeout to some seconds.

set timeout
Gopi Sekar
Honored Contributor

Re: Expect script - ftp problem


dont make expect very strict, it does not like it some times.

modify your script to expect for password: and continue with it. also always give a timeout in scripts so that the script never gets blocked for any reason.

Regards,
Gopi
Never Never Never Giveup
Nick D'Angelo
Super Advisor

Re: Expect script - ftp problem

Amit, thank you - your tip worked.

Now, it seems to hang on the exit.

When I run the ../expect script.exp, it runs, transfers the file and it returns with the ftp> prompt.

Nickd
Always learning
Nick D'Angelo
Super Advisor

Re: Expect script - ftp problem

Gents, I looked at my script again and I have it figured out.

I had some more expect exacts that it was looking for.

If you wan full points, please reply and I will assign for you.

You gotta love this forum.

nickd
Always learning
Gopi Sekar
Honored Contributor
Solution

Re: Expect script - ftp problem


who does not want full points :)

here is the other problem you faced and fixed.

after put, you are expecting

200 PORT command successful.\r
150 Opening ASCII mode data connection for nd.test.\r
226- Transfer complete - acknowledgment message is pending.\r
226- Transfer complete - acknowledgment message is pending.\r
226 Transfer complete (Batch Number = 8150).\r
115 bytes sent in 0.01 seconds (10.09 Kbytes/s)\r

of this the final output line could change everytime depending on your bandwidth (10.09 kbytes/s) so remove that line and you should be safe.

Regards,
Gopi
Never Never Never Giveup
Muthukumar_5
Honored Contributor

Re: Expect script - ftp problem

Just curious that, we can use ftp batch mode to do it easily as,

ftp -i -n <<-EOF
open
get file
put file
bye
EOF

It will do it easily.

hth.
Easy to suggest when don't know about the problem!
Nick D'Angelo
Super Advisor

Re: Expect script - ftp problem

FYI.

I had to use expect due to the fact that I needed to connect to a specific outbound ftp proxy first.

Then, I needed to connect to the outside ftp site using the account@ftpsite.com and password type of idea.

Thanks.

Nick
Always learning