Only fclose($fp) when $mode & NET_SFTP_LOCAL_FILE.