Purchase: Once you have a fully executed contract you will be required to put an EMD (Earnest money deposit) into escrow. This is your good faith deposit and will take the property off the market. At closing, the remaining items of cost will be required as well as your down payment.
Refinance: Closing costs will be due at close when you sign your final loan documents. You can either roll these fees inside your new loan amount or pay out of your pocket.