The files in one of our servers can be accessed via http. So, when we bring up a url similar to the following, we get a list of files/directories in that location:
http://mytestserver/files/
From this list, I need to select only those files that match a regex format.
If this was a location in the disk, I can make use of the method eachFileMatch and filter the files that I need.
Can someone help me how we can do this from a http URL?
I would think it would be far better to put an FTP server there, if you want to serve files.
Unless your HTTP server supports a known file serving protocol such as WebDAV, you're going to have to jump through some hoops to use it as a file server.
You would need to use a HTTP client, such as the Groovy HttpBuilder.
When you make a request to that URL, your HTTP server returns a response. If you have directory listings enabled, then most HTTP servers will return a HTML page providing you with links to the files and subdirectories within that directory.
You would need to parse that HTML response, perhaps using some regular expressions to extract the file links that you want from it.
But every HTTP server returns such listings in its own format, so you would have to adapt it to the format used by your server.
expadnded version of Grooveek code with https and providing cookie to get to webdavs behind login/password:
Another version of @tim_yates Answer using JSoup
No, you'll need to do some parsing of the returned HTML.
Given this page as an example: http://central.maven.org/maven2/com/bloidonia/groovy-stream/
We'd need to do something like:
Which prints out:
Obviously, you'd need to tweak the
body.pre.a
bit to match the output of your webserver for directory listings