$s = Net::SFTP::Foreign->new(...); if ($s->error) { die "Unable to connect to remote host: " . $s->error }