swaroop has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am trying to get the files using scp.
***************************************************

$timeout = 5; $scp_command = "$SCP -v -r remoteuser@remote_host:/tmp/test /tmp/"; $Scp = Expect->spawn($scp_command); $Scp->log_stdout(0); $Scp->exp_internal(1); while ( $Scp->expect(2,"Are you sure you want to continue connecting ( +yes/no)?") ) { print $Scp "yes\n"; } sleep(60); $Scp->expect(1,"password:"); print $Scp "$password\n"; $Scp->soft_close(); $Scp->hard_close();
************************************************

The problem is some times i am getting less files , some times no files. What could be the problem ? How can I wait till the files transfered ?

Please help.

20050413 Janitored by Corion: Added code tags, more formatting

Replies are listed 'Best First'.
Re: Expect problem
by naChoZ (Curate) on Apr 12, 2005 at 23:07 UTC

    You're killing a rabbit with an h-bomb. Just set up ssh keys as friedo previously suggested to you and you can easily automate your scp operation.

    --
    "This alcoholism thing, I think it's just clever propaganda produced by people who want you to buy more bottled water." -- pedestrianwolf

    updated: corrected link per ikegami.

Re: Expect problem
by jbrugger (Parson) on Apr 13, 2005 at 04:58 UTC
    Why don't you just use Net::SCP?
    (taken from the docs)
    #procedural interface use Net::SCP qw(scp iscp); scp($source, $destination); iscp($source, $destination); #shows command, asks for confirmation, +and #allows user to type a password on tty #OO interface $scp = Net::SCP->new( "hostname", "username" ); #with named params $scp = Net::SCP->new( { "host"=>$hostname, "user"=>$username } ); $scp->get("filename") or die $scp->{errstr}; $scp->put("filename") or die $scp->{errstr}; #tmtowtdi $scp = new Net::SCP; $scp->scp($source, $destination); #Net::FTP-style $scp = Net::SCP->new("hostname"); $scp->login("user"); $scp->cwd("/dir"); $scp->size("file"); $scp->get("file"); $scp->quit;

    ps. as stated above:
    Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module?
    A: You don't. Use RSA or DSA keys. See the ssh-keygen manpage

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      Hi , Thanks .. humm.. its kinda big process to get these module in my env. Please tell me the problem in my script ? thanks
        Got it , We need to use $scp->expect(undef) after sending the password.