How to automate login and download from website?

My C++ program needs to send a username and password to a website, then search for a file in that website and also download it.
(Instead of manually logging in and downloading through a browser,
I'm trying to make a program do it for me).