in reply to SCP connection

I would suggest that you check out the module from CPAN called Net::SCP. It should be able to do what you are looking to do.

With regard to getting the password into the script. This isn't secure practice. A slightly more secure practice would be to generate a pwless ssh key and use that key to connect to the server.

use Net::SCP qw(scp); my ($host, $username) = ("example.com", "eric"); $scp = Net::SCP->new( { "host"=>$hostname, "user"=>$username } ); for my $file (@files) { $scp->put($file) or warn $scp->{errstr}; }

However, if you are really intent on hard-coding the password into the server, then consider using Net::SSH2. It allows all the different types of authentication.

use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect('example.com') or die ("SSH2 Connect Error: $!"); if ($ssh2->auth_keyboard('password')) { for my $file (@files) { scp_put($file); } }

Note: All the code is untested.

Replies are listed 'Best First'.
Re^2: SCP connection
by rodion (Chaplain) on Jul 24, 2006 at 20:36 UTC
    Net::SSH::Perl has a perl-only implementation of SSH-1 and SSH-2, with a variety of authentications schemes. The docs identify some performance advantages to being all perl, but more relevant here they say
    It also simplifies the process of using password-based authentications; when writing a wrapper around ssh you probably need to use Expect to control the ssh client and give it your password. Net::SSH::Perl has built-in support for the authentication protocols, so there's no longer any hassle of communicating with any external processes.
Re^2: SCP connection
by mantra2006 (Hermit) on Jul 24, 2006 at 20:00 UTC
    hey thanks for the reply..where can I get Net::SCP qw(scp); or Net::SSH2; and where do I copy these files in my directory?
        Hello If I use
        $ ppm install Net-SSH2 Installing package 'Net-SSH2'... Error installing package 'Net-SSH2': Could not locate a PPD file for p +ackage Net-SSH2
        does this mean SSH2 is not there on server?