BEGIN { eval { require Net::SSH2; 1 } or eval { require Net::OpenSSH::Compat::SSH2; Net::OpenSSH::Compat::SSH2->import(':supplant'); 1; } or die "unable to load any SSH module"; Net::SSH2->import(); } #### use strict; use warnings; use Data::Dumper; my %connection_details = ( host => 'localhost', @ARGV); my $SFTP = SFTP_connection(%connection_details); print "SFTP: ", Dumper($SFTP), "\n"; exit (0); BEGIN { eval { require Net::SSH2; warn "Net::SSH2 loaded"; 1; } or eval { require Net::OpenSSH::Compat::SSH2; Net::OpenSSH::Compat::SSH2->import(':supplant'); warn "Net::SSH2 supplanted"; 1; } or die "unable to load any SSH module: $@"; Net::SSH2->import(); } sub SFTP_connection { my (%connection_info) = @_; ## Connect to the sFTP server my $SFTP = Net::SSH2->new(); $SFTP->connect($connection_info{'host'},22) or die "Unable to connect to the remote sFTP server \n\n $@"; ## Login to sFTP server $SFTP->auth_password($connection_info{'user'},$connection_info{'pass'}) or die "Unable to login Check username and password. \n\n $@\n"; return $SFTP; }