I'll speak in terms of Apache httpd, since it's a very popular webserver.
The root directory where all files are kept, is generically named DocumentRoot.
Please bear in mind that files are kept in DocumentRoot for being served by the web server, not for being shown to you when you log in via FTP. FTP is a totally different protocol that is not related to web sites and in this context it is just a way to allow you, the user, modify/update files on a remote server.
The www / public_html directory that you talk about in your question is probably not DocumentRoot. This is additional functionality of Apache, the mod_userdir module. Please consult its documentation.
As said in the docs, there's an UserDir setting in Apache's configuration file which lets you customize the name of these user directories, from where the web server will serve the sites that belong to different users.
Since there's no restriction on UserDir, you can have anything there, even foobar. You can judge by the content of this directory (HTML files, images) that this can be an user directory that holds a site that's being exposed by Apache. But I'd say that doing this automatically with a script seems unreliable to me. Not to mention that for example you can have a public_html directory that is not an user directory, its name matching the default value for Apache UserDir setting being just a simple coincidence. Ideally, in order to judge about a directory if it's an UserDir, you'll need access to the configuration file of the web server. And normally you don't have it. Web hosting providers can put at most user-specific logs in your home directory.
To summarize: if you need to perform any actions with the user directory, have it come to your script as input data: command-line argument, setting from a config file etc, but do not try to guess it.