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

I am using Net::SFTP::Foreign in a script to connect to multiple remote servers. I have successfully used the key_path argument to connect to the first server using the DSA key:

%args = (user=>$f_user, key_path=>'/path/to/id_dsa', port=>$port);
But I need a the RSA key to connect to the next server. Is it possible to load both keys in to the key_path? If so, what is the syntax?

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign key_path
by salva (Canon) on Mar 15, 2012 at 17:07 UTC
    As you have to create a Net::SFTP::Foreign object for every remote server, just use the correct arguments for every host.
    $sftp1 = Net::SFTP::Foreign->new($host1, key_path => '/path/to/id_dsa' +); $sftp2 = Net::SFTP::Foreign->new($host1, key_path => '/path/to/id_rsa' +); ...
    You can also put that information on ~/.ssh/config (see ssh_config).