Help Using Expect

From: Jim (nep777_at_yahoo.com)
Date: 06/30/04


Date: 30 Jun 2004 11:46:21 -0700

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


Relevant Pages

  • Can fputs() onto an sftp host work ?
    ... The host I am trying to write to is sftp only. ... I have uploaded my script onto ... Does an sftp server require security checks even when writing to and ... newfile.txt and if i comment this it dies on fopen. ...
    (alt.php)
  • Re: TCPIP Services SFTP
    ... cannot get the session to terminate when I am done. ... at the sftp> prompt and the VMS session hangs. ... get the TCPIP Services sftp to terminate the connection? ... sftp> exit ...
    (comp.os.vms)
  • Re: How to filter string for words that meet a certain criteria?
    ... Lasse Kliemann wrote: ... sftp> ls -1 *.txt ... sftp> exit' ... He just isn't quoting his output variable properly so he's losing the white space. ...
    (comp.unix.shell)
  • Reg:REgular expressionn
    ... HI iam new to expect and regular expression not sure whats the problem ... dbg 0 "Established sftp session " ...
    (comp.lang.tcl)
  • How can I capture sftp session info from a shell script?
    ... I got to use sh output to capture from a sftp put ... sftp> exit ... Uploading file1 to ... ... How can I capture the put progress info? ...
    (comp.unix.shell)