Update sketch via wan network

Hello everyone. I would like to know how I can update the sketch in a Nodmcu through a wan network. I also need to know if once the sketch update is finished, whether it has been updated correctly or if it is corrupted, the connection is automatically resumed.

Thank you.