Home: Perl Programming Help: Advanced:
SCP a folder from local machine to remote machine...!



autoworld
Novice

Aug 29, 2010, 1:24 AM


Views: 5916
SCP a folder from local machine to remote machine...!

Hi all,

I am trying fo automate few test cases. I need to send a folder to a remote system using SCP. I have done ssh to the remote machine and passed scp as shell command. I am finding it tough to give password for the scp.. Please help...



#!/usr/bin/perl

use Net::SSH::Perl;

my $host = "192.168.200.254";
my $user = "root";
my $password = "root";




#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
sleep(3);
$ssh->login($user, $password);
sleep(2);

#need to enter password after scp. please help...!
$ssh->cmd("scp -r user@192.168.200.165:/home/user/1020_exe 1020_exe");

sleep (5);

$ssh->cmd("cd 1020_exe");
sleep(1);

$ssh->cmd("chmod 777 *");
sleep(1);


$ssh->cmd("./hello");
sleep(1);


(This post was edited by autoworld on Aug 29, 2010, 1:31 AM)


FishMonger
Veteran / Moderator

Aug 29, 2010, 8:46 AM


Views: 5900
Re: [autoworld] SCP a folder from local machine to remote machine...!

The best approach would be to use ssh key exchange instead of passing the credentials in the script. However, based on your other post, you've decided to use Expect.

Why do you have all of those unnecessary sleep commands?


autoworld
Novice

Aug 29, 2010, 6:08 PM


Views: 5882
Re: [FishMonger] SCP a folder from local machine to remote machine...!

Hi,

Thank you for your help. i decided to use password beacuse I am login into a processor, where all the files will get deleted after reboot. So that public key should be passed each time. I ll remove those sleeps.


autoworld
Novice

Aug 31, 2010, 11:09 PM


Views: 5730
Re: [FishMonger] SCP a folder from local machine to remote machine...!

Hi,

I want to create a user in remote machine using ssh. Please help me in giving the password after adduser command. I need to wait for the prompt "New password:" .


#!/usr/bin/perl

use Net::SSH::Perl;

my $host = "192.168.200.254";
my $user = "root";
my $password = "root";

#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
sleep(3);
$ssh->login($user, $password);
sleep(2);
$ssh->cmd("adduser thomas");
sleep(1);
$ssh->print("thomas123"); #wrong method
sleep(4);
$ssh->print("thomas123"); #wrong method


FishMonger
Veteran / Moderator

Sep 1, 2010, 5:00 AM


Views: 5720
Re: [autoworld] SCP a folder from local machine to remote machine...!

Use the -p switch and specify the encrypted password in the adduser command.