sub sftp_file { my ($file,$destfile,$host,$port,$user,$privpath,$pubpath,$pass) = @_; my $ssh2 = Net::SSH2->new(); $ssh2->connect( $host,$port ) or $logger->info("Connect failed: $!\n"); if ( !$ssh2->error ) { $ssh2->auth( username => $user, publickey => $pubpath, privatekey => $privpath, password => $pass, passphrase => undef ) or $logger->info("Authent ication failed: $!\n"); } if ( $ssh2->auth_ok ) { my $sftp = Net::SFTP::Foreign->new( ssh2 => $ssh2, backend => 'Net_SSH2' ); $sftp->error and $logger->info("Unable to establish SFTP connection: $sftp->error\n"); $sftp->put( "$file", "$destfile", best_effort => 1 ) or ( $logger->info("Put failed: $sftp->error\n") && return ); return 1; } else { return 0; } }