Need help sending a password to ftp

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
 
K

kz

joe said:
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

What is precisely your Perl question?

Rgds,

Zoltan
 
D

David Efflandt

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

Since this is a Perl newsgroup, you might try using Perl module Net::FTP
(in libnet group of modules) and Net::Telnet (separate module).
 
M

Martien Verbruggen

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:
#!/usr /bin/expect

Obviously, this is not a Perl program but an expect program, and you
shouldn't be asking the question here. Maybe comp.unix.shells would be
a good place. i don't really know.

However, there is a Perl module called Expect
(http://search.cpan.org), which can be used to do what you want. There
is also Net::Telnet.

You might be able to use Net::FTP. I am not certain how I should
interpret your description up there. You seem to be saying that you
want to telnet to the remote machine, then from there FTP files back
to the machine you came from? If the remote machine has an FTP serve,
you can use that. Maybe it supports other transfer protocols (rcp,
scp), for which modules are available.

Martien
 
H

Himanshu Garg

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


Did you try Expect.pm. It also has a sample script that does ftp. You
might want to take a look at it.

Ofcourse you have the other alternatives of using readymade modules
mentioned in other replies.

++imanshu
 
J

Joe Smith

joe said:
expect -gl "331 Password required for*"
expect -gl "Password:*"
send "$password \r"

Use Expect.pm and don't put an additional blank at the end of the password.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top