Help Using Expect

Discussion in 'Perl Misc' started by Jim, Jun 30, 2004.

  1. Jim

    Jim Guest

    Hi
    I am using expect to automate sftp file transfers. It works fine for
    files under 1MB. However it dies when It tries to grab big files. It
    seems to always die at 1.4MB. If I sftp manually, there is never a
    problem. Also, if I run the script to connect to the server, then go
    interactive (by using expect's interactive routine) it works. I have
    tried everything from the expect.pm documentation. Here is the
    relevant code.
    Thanks for any suggestions

    ---
    #!/db/app/perl/bin/perl -w
    use Expect;

    $cmd = '/appl/uas/ssh/bin/sftp user@host';
    $pw = 'mypassword';
    $lcd = '/temp/raw_downloads';

    # switch to local dir where the xferd files should go
    chdir $lcd;

    # spawn the sftp program
    my $sftp = Expect->spawn($cmd) or die "Can't spawn cmd: $!";
    # $sftp->log_stdout(0);

    # wait 10 seconds for password prompt:
    unless ( $sftp->expect(10, -re , '.*assword:') ) {
    print "timed out or something else went wrong\n";
    exit;
    }

    print $sftp "$pw\r";

    # wait for sftp shell prompt:
    unless ( $sftp->expect(10, -re , 'sftp>') ) {
    print "timed out or something else went wrong\n";
    exit;
    }

    # cd to the remote server dir to grab the files from
    $sftp->send("cd /u10/seatab\r");

    ### IF I GO INTERACTIVE HERE, IT WORKS ######
    # $sftp->interact();

    # wait for the next shell prompt:
    unless ( $sftp->expect(10, -re , 'sftp>') ) {
    print "timed out or something else went wrong\n";
    exit;
    }

    # grab the files
    ###### THIS IS WHERE IT DIES. #####
    $sftp->send("mget TRANSACT*\r");

    $sftp->soft_close();

    ................
    Jim, Jun 30, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raphael Bossek
    Replies:
    1
    Views:
    729
    Ganesan R
    Aug 18, 2003
  2. Simon Strandgaard

    how to expect eof with expect+pty

    Simon Strandgaard, Dec 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    336
    Simon Strandgaard
    Dec 20, 2006
  3. Phil
    Replies:
    0
    Views:
    157
  4. Replies:
    0
    Views:
    90
  5. Slain

    Using Expect.pm

    Slain, May 8, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    89
    Slain
    May 8, 2007
Loading...

Share This Page