http://www.perlmonks.org?node_id=838026

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

I am trying to copy a file securely to my server. using the following line

system('scp -P 223 /home/my/local/file/whatever.txt root:root_password +\@foo.bar.com:/my/remote/path_name');
when I run it I get the following error:
ssh: Could not resolve hostname root: Name or service not known

what is going on?

Replies are listed 'Best First'.
Re: SCP help
by ikegami (Patriarch) on May 03, 2010 at 05:08 UTC
    You would have gotten the same result from the prompt. Your problem has nothing to do with Perl.
    root:root_password@foo.bar.com:/my/remote/path_name
    means file root_password@foo.bar.com:/my/remote/path_name on machine root. The path should be
    root@foo.bar.com:/my/remote/path_name
    You could feed the password to its STDIN (probably), but it would be better if you used public key authentication (so you don't need to specify a password at all).
      You could feed the password to its STDIN (probably)
      Not really, ssh opens /dev/tty and reads the password from there.
Re: SCP help
by codeacrobat (Chaplain) on May 03, 2010 at 06:23 UTC
    Hello, there are perl modules for this kind of job, e.g. Net::SFTP::Foreign, Net::SSH2. Maybe these modules help you to integrate ssh better into your perl scripts.

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      ... and Net::OpenSSH that being on an Unix OS, maybe Linux, it's probably the easiest one to install and use for SCP file copy.
      use Net::OpenSSH; my $ssh = Net::OpenSSH->new('root@foo.bar.com', passwd => $passwd, port => 223); $ssh->scp_put("/home/my/local/file/whatever.txt", "/my/remote/path_name");
Re: SCP help
by nagalenoj (Friar) on May 03, 2010 at 05:59 UTC

    If it's not an interactive kind of script, you could try copying the public key to the authorized keys file. ssh without password linux

    But, here the problem is in your syntax.