Hmm. Via an http connection? Open a socket, request the file, look through the headers as they arrive for a Content-Length header, read what it says if it's there. Once you've found that (or determined that it's not there to find), you can close the socket without reading any more.
If there is no Content-Length header, then you'll have to read the entire file and find out its size for yourself. At least, that's with http. Other protocols (such as ftp) may be more forthcoming if they're available.