use Net::SFTP::Foreign; my $host = 'localhost'; my $user = 'sshuser'; my $privateKey = "C:\\id_rsa"; my $file = "C:\\sshuser-results.xml"; my $passphrase = "password"; my $sftp = Net::SFTP::Foreign-> new(host => $host, backend => 'Net_SSH2', user => $user, key_path => $privateKey, passphrase => $passphrase, ); if( not $sftp) { $sftp->die_on_error("Unable to establish SFTP connection"); } elsif($sftp->error) { $sftp->die_on_error("Connect Failed: " .$sftp->status); } else { print "Connected!\n"; if($sftp->get("sshTest.txt")) { print "get success: " . $sftp->status . "\n"; } else{ print "get failed: " . $sftp->error . "\n"; } if($sftp->put($file)){ print "put file success \n"; } else{ print "put failed: " . $sftp->error . "\n"; } }