use strict; use Expect; my $sftpPassword = "useracctPW"; open FTP_CARDS, "$ARGV[0]/sftp_CMS.cards" or die $!; # Uncomment the following line if you want to see what expect is doing # $Expect::Exp_Internal = 1; # Create the Expect object and create the message log file. my $params = " -oPort=10022 useracct\@sftp.section111.cms.hhs.gov"; my $command = "/usr/bin/sftp $params"; my $exp = Expect->spawn("$command") or die "Cannot spawn sftp command \n"; $exp->timeout(600); ## [this does not append ]$exp->log_file("$ARGV[0]/sftp_CMS.log", "w"); $exp->log_file("$ARGV[0]/sftp_CMS.log"); $exp->log_stdout(0); # Wait for Password prompt to show up then send it back $exp->expect(30, ["Password:"]); ## $exp->expect(30, ["useracct\@sftp.section111.cms.hhs.gov's password:"]); $exp->send("$sftpPassword\n"); # Execute each sftp command found in the input file of commands while (my $ftp_command = ) { # Wait for sftp prompt $exp->expect(600, ["sftp>"]); $exp->send("$ftp_command\n"); } # Destroy the expect object $exp->soft_close();