Need help sending a password to ftp

From: joe (joez3_at_yahoo.com)
Date: 03/02/04


Date: 2 Mar 2004 07:23:47 -0800

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



Relevant Pages

  • Problems getting ftp to take my password
    ... 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. ... 530 Login incorrect. ...
    (comp.lang.perl.modules)
  • Re: Need help sending a password to ftp
    ... > then bring up ftp on that system to transfer some files over there. ... > can get the telnet session open. ... The script fails with: ... > 530 Login incorrect. ...
    (comp.lang.perl.misc)
  • Re: Need help sending a password to ftp
    ... > then bring up ftp on that system to transfer some files over there. ... > can get the telnet session open. ... The script fails with: ... > 530 Login incorrect. ...
    (comp.lang.perl.misc)
  • Re: Script for telnet server to communicate with J2EE application
    ... Is there any way that this script automatically get invoked as the ... Telnet Client login to Server? ... As you were asking about using telnet client classes to allow your Java application to talk to a telnet server, I was assuming you'd want to use something like the following to login, send one barcode to the telnet server and logout again: ...
    (comp.lang.java.programmer)
  • Expect, telnet, frozen console.
    ... telnet into remote host, provide username/password, surrender control to ... This script will eventually be tied into /etc/inittab so that it ... app called 'loe' which presents a login screen in 80x24 ASCII a la ...
    (comp.lang.tcl)