in reply to My Perl/Expect script aborts when sftp connection stalls at remote destination

Does the hang-up occur when running the sftp commands on the command line? You could also try Net::SFTP::Foreign or Net::SFTP (lots of dependencies for this one). I find working with those packages to be a little better with respect to exception handling for doing SFTP.

  • Comment on Re: My Perl/Expect script aborts when sftp connection stalls at remote destination

Replies are listed 'Best First'.
Re^2: My Perl/Expect script aborts when sftp connection stalls at remote destination
by Anonymous Monk on Feb 24, 2010 at 19:52 UTC
    First, zow, thanks for the quick reply. When connected manually I see the 1-line status info line progressing through from 0% to 100%, with the sporadic message of stalled. But it finishes. For the script's run it seems to just cut off, maybe at the first stall, as if I did a kind of "kill" command from the UNIX command line. As to switching to Net::SFTP, that'd be a tough switch since our script is already in production and we don't have Net::SFTP in our shop at this point. I know it sounds dumb to have a frail app in production. Most future files are expected to be small enough that the problem vanishes, and I can manually get the rare files that are too big. ALSO, I'll see if a late night run of the script, when the traffic should be much lower, avoids the problem.
      Is there any reason not to use the complete expect to run this? The PERL module is not a fully implementation of expect as far as I know. I recall from Don Libes book ( the writer of expect) that there is excellent handling of exceptions you speak of in native expect. I'd be interested to give this some more thought as I use native expect in a PERL shop. I have been thinking of using the module, but found that Expect is a complete language!
      Really, forget about solving your problem with Expect and use one of the Perl SFTP modules. It doesn't matter how hard it is to get it or a new version of the script in production. Properly done, your file transfers will be reliable and you will not have to worry about them anymore. It will pay back!

      My own recommendation is to go with Net::SFTP::Foreign, but I am the author, not completely unbiased!

      One other thing that I noticed is that in your while loop over your commands you are calling the expect method with the 600 sec timeout before the send method. Perhaps it is still using a default timeout?