my $sftp = Net::SFTP::Foreign->new($host, password => $password); if ($sftp->error) { # Send the email. }