I'm using Expect to automate an sftp session with a site that only uses passwords, not ssh keys. It worked fine until it tried retrieving an oversized file. The session log indicated the connection "stalled"
too much traffic & users on remote site and my script terminated. I tried upping the timeout parm in the comand '$exp->expect(600,
"sftp>");' that's waiting for the sftp prompt once the file get is done, but it didn't help. It bombed well before the 10 minutes passed. Since I can expect the transmission to stall almost every time, I can't just use a loop to check the session log and try again. Is there anything deeper in Perl or Expect that I could use to help my script cope with stalled transmissions?
Thanks, in advance, for any ideas or suggestions.
------------------------------
at the risk of violating a posting rule on over-bloated questions, here is the script. It reads in a file of the actual sftp commands but they are just vanilla puts or gets mostly.
------------
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 = <FTP_CARDS>) {
# Wait for sftp prompt
$exp->expect(600, ["sftp>"]);
$exp->send("$ftp_command\n");
}
# Destroy the expect object
$exp->soft_close();
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.