#!/usr/bin/expect -- # (eeman "expect" 491) # (find-fline "/usr/lib/tcl8.0/") # (find-fline "/usr/doc/tk8.0/") # (find-vldifile "tcl8.0-dev.list") # (eeman "tclvars") # (eeman "tclsh" "VARIABLES") # (eeman "3tcl expr") # (eeman "3tcl proc") # (eeman "3tcl lrange") # (eeman "3tcl foreach") # Note: ftp won't ask for login name and password for machines listed # in .netrc, and will use the login and password taken from there; for # other machines this script will use "anonymous" and (duh!) # "edrx@inx.com.br". # # Examples of usage: # ~/EXPECT/anonftp ftp.debian.org 'cd debian' dir # ~/EXPECT/anonftp ftp.debian.org 'cd debian' dir quit # ~/EXPECT/anonftp ftp://ftp.debian.org/debian/ dir quit # # If you don't give a "quit" then expect will let you interact with # the ftp program after finishing the execution of the commands given # as arguments. if {$argc==0} { send_error "Usage: anontfp \[-q\] machine \[command \[command ...\]\]\n" exit 1 } set timeout -1 if {[lindex $argv 0]=="-q"} { log_user 0; set argv [lrange $argv 1 end] } # Convert an ftp url to a machine name and a "cd" command if {[regexp {^ftp://([^/]*)(/.*)?$} [lindex $argv 0] -> host path]} { # puts =$host= # puts =$path= set argv [concat [list $host "cd $path"] [lrange $argv 1 end]] puts "argv now: $argv" } spawn ftp [lindex $argv 0] while 1 { expect { -re "\nName.*:" { send "anonymous\n" } "\nPassword:" { send "edrx@inx.com.br\n" } "\nftp>" { break } } } proc ftpdo {args} { send "[concat $args]\n" expect "\nftp>" {} eof {exit} } ftpdo hash on ftpdo prompt off if {![log_user]} { send_user "ftp>"; log_user 1 } foreach command [lrange $argv 1 end] { eval ftpdo $command } interact