J
joe
I need to create a perl/expect script that will telnet into a system
then bring up ftp on that system to transfer some files over there. I
can get the telnet session open. I then start up ftp but that looks
like it doesn't take my password. The script fails with:
331 Password required for moose .
Password:
530 Login incorrect.
Login failed.
ftp> cd /tmp
530 Please login with USER and PASS.
This is what my script looks like:
#!/usr /bin/expect
# Usage: "hold HOST USER PASS".
# Action: login to node HOST as USER. Offer a shell prompt for
# normal usage, and also print to the screen the word HELD
# every five seconds, to exercise the connection periodically.
# This is useful for testing and using WANs with short time-outs.
# You can walk away from the keyboard, and never lose your
# connection through a time-out.
# WARNING: the security hazard of passing a password through the
# command line makes this example only illustrative. Modify to
# a particular security situation as appropriate.
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set server [lindex $argv 3]
# There's trouble if $username's prompt is not set to "...} ".
# A more sophisticated manager knows how to look for
different
# prompts on different hosts.
set prompt_sequence "} "
spawn telnet $hostname
expect "login: "
send "$username\r"
expect "Password:"
send "$password\r"
# Some hosts don't inquire about TERM. That's another
# complexification to consider before widespread use
# of this application is practical.
# Note use of global ? pattern matching to parse "*"
# as a wildcard.
expect -gl "TERM = (*)"
send "\r"
expect $prompt_sequence
send "cd /opt/SUNWsymon/base/bin \r"
expect $prompt_sequence
send "ftp $hostname \r"
expect "Name ($server:$username):"
send "$username \r"
expect -gl "331 Password required for*"
expect -gl "Password:*"
send "$password \r"
expect "230 User $username logged in."
expect "ftp>"
send "cd /tmp \r"
interact
then bring up ftp on that system to transfer some files over there. I
can get the telnet session open. I then start up ftp but that looks
like it doesn't take my password. The script fails with:
331 Password required for moose .
Password:
530 Login incorrect.
Login failed.
ftp> cd /tmp
530 Please login with USER and PASS.
This is what my script looks like:
#!/usr /bin/expect
# Usage: "hold HOST USER PASS".
# Action: login to node HOST as USER. Offer a shell prompt for
# normal usage, and also print to the screen the word HELD
# every five seconds, to exercise the connection periodically.
# This is useful for testing and using WANs with short time-outs.
# You can walk away from the keyboard, and never lose your
# connection through a time-out.
# WARNING: the security hazard of passing a password through the
# command line makes this example only illustrative. Modify to
# a particular security situation as appropriate.
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set server [lindex $argv 3]
# There's trouble if $username's prompt is not set to "...} ".
# A more sophisticated manager knows how to look for
different
# prompts on different hosts.
set prompt_sequence "} "
spawn telnet $hostname
expect "login: "
send "$username\r"
expect "Password:"
send "$password\r"
# Some hosts don't inquire about TERM. That's another
# complexification to consider before widespread use
# of this application is practical.
# Note use of global ? pattern matching to parse "*"
# as a wildcard.
expect -gl "TERM = (*)"
send "\r"
expect $prompt_sequence
send "cd /opt/SUNWsymon/base/bin \r"
expect $prompt_sequence
send "ftp $hostname \r"
expect "Name ($server:$username):"
send "$username \r"
expect -gl "331 Password required for*"
expect -gl "Password:*"
send "$password \r"
expect "230 User $username logged in."
expect "ftp>"
send "cd /tmp \r"
interact