When the property is sold, enough of the proceeds shall be paid into the treasury of the county or city to satisfy the lien and the costs, and the surplus, if any, shall be paid to the owner of the property, if known, and if not known shall be paid into the court for the use of the owner when ascertained.