CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Sending files with Net::SCP

 



wtb
Novice

Dec 18, 2009, 8:24 AM

Post #1 of 3 (1543 views)
Sending files with Net::SCP Can't Post

Hello,


I'm trying to send/receive files between 2 servers using the Net::SCP module but it doesn't work. I need your help! :)

If i do :

Code
 # scp file.txt administrator@server:/dest_dir


It works fine, asks me the password for administrator and sends the file.txt.

But when I try to use the Net::SCP I get an error :

Simple way

Code
use Net::SCP qw(scp iscp); 

my $source = "/source_dir/";
my $destination = "/dest_dir/";

scp($source, $destination);
iscp($source, $destination);

my $scp = Net::SCP->new( "IP", "administrator" );
$scp->put("myfile") or die $scp->{errstr};
$scp->quit;


Or with the FTP style

Code
$scp = Net::SCP->new("IP"); 
$scp->login("administrator");
$scp->cwd("/dest_dir");
$scp->size("myfile");
$scp->put("myfile") or die $scp->{errstr};
$scp->quit;


I always have this result : LOST CONNECTION.

And don't know why...


Thanks


1arryb
User

Dec 18, 2009, 8:48 AM

Post #2 of 3 (1539 views)
Re: [wtb] Sending files with Net::SCP [In reply to] Can't Post

Hi wtb,

RTM Smile. From the Net::SCP perldoc:

Quote
Q: How do you supply a password to connect with ssh within a perl
script using the Net::SSH module?

A: You don't (at least not with this module). Use RSA or DSA keys.
See the
quick help in the next section and the ssh-keygen(1) manpage.


Cheers,

Larry


(This post was edited by 1arryb on Dec 18, 2009, 9:11 AM)


wtb
Novice

Dec 19, 2009, 4:22 AM

Post #3 of 3 (1517 views)
Re: [1arryb] Sending files with Net::SCP [In reply to] Can't Post

I've done it but for root user and I forgot that on my remote host it's not possible to connect with root... Now it works :)

Thanks.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives