tags:

views:

6523

answers:

3

Hello,

I know it is not recommended, but is it at all possible to pass the users password to scp? I'd like to copy a file via scp as part of a batch job and the receiving server does of course need a password (no, I cannot easily change that to key-based authentication).

TIA

Argelbargel

+4  A: 

You can script it with a tool like expect (there are handy bindings too, like Pexpect for Python).

Pat Notz
+5  A: 

Here is an example of how you do it with expect:

sub copyover {
    $scp=Expect->spawn("/usr/bin/scp ${srcpath}/$file $who:${destpath}
+/$file");
    $scp->expect(30,"ssword: ") || die "Never got password prompt from
+ $dest:$!\n";
    print $scp 'password' . "\n";
    $scp->expect(30,"-re",'$\s') || die "Never got prompt from parent 
+system:$!\n";
    $scp->soft_close();
    return;
}
Espo
+1  A: 

An alternative would be add the public half of the user's key to the authorized-keys file on the target system. On the system you are initiating the transfer from, you can run an ssh-agent daemon and add the private half of the key to the agent. The batch job can then be configured to use the agent to get the private key, rather than prompting for the key's password.

This should be do-able on either a UNIX/Linux system or on Windows platform using pageant and pscp.

rjray