Scp with pending module not working

I wrote the following program to automate the scp command in perl.

#!/usr/bin/expect
spawn scp hscpe@9.126.134.54:/home/hscpe/output.txt imt
set pass "jujsa32s"
expect {
        password: {send "$pass\r"; exp_continue
     }

      

But no file transfer happens. Usually on the console if I tried the same scp command it works fine. Can anyone figure out the problem

Thanks in advance!..

+3


source to share


3 answers


use Net :: OpenSSH :



my $ssh = Net::OpenSSH->new('hscpe@9.126.134.54', password => 'jujsa32s');
$ssh->scp_get('/home/hscpe/output.txt', 'imt/output.txt');

      

+2


source


You are using wait for your password.
I think you should be using expect.pm for this task. The environment used when running the perl script may miss expected parts.



0


source


You must use "sshpass" in your bash script:

#!/bin/bash
sshpass -p "password" scp -r user@example.com:/some/remote/path /some/local/path

      

0


source







All Articles