#!/usr/bin/perl use warnings; use strict; use Net::SSH2 qw(LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE LIBSSH2_CHANNEL_FLUSH_ALL LIBSSH2_HOSTKEY_POLICY_ASK); my $pass = 'rumpelstiltskin'; my $ssh2 = Net::SSH2->new( debug => 1 ); $ssh2->trace(-1); $ssh2->timeout(5000); $ssh2->connect('my.net') or $ssh2->die_with_error; $ssh2->auth_publickey('me', '/home/me/.ssh/id_rsa.pub', '/home/me/.ssh/id_rsa', $pass ); my $sftp = $ssh2->sftp(); my $fh = $sftp->open('/etc/passwd') or $sftp->die_with_error; print $_ while <$fh>; return 0; __END__