#!/bin/env perl use strict; use warnings; use Net::SFTP::Foreign (); my ( $host, $user, $timeout ) = ( '', '', 30 ); # typically from a subroutine call my $sftp = Net::SFTP::Foreign->new( host => $host, user => $user, timeout => $timeout, more => [ -i => "/some/path/to/$user/.ssh/id_dsa", # the path to your key file -o => 'PreferredAuthentications=publickey', '-v', ], );