Question : Help Using Expect

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();

...............

Answer : Help Using Expect

The soft_close method only waits 15 seconds. Perhaps you need to insert a longer wait, looking for the prompt after the mget command:

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

$sftp->send( "quit\r");

and before the soft_close.
Random Solutions  
 
programming4us programming4us