1

I am trying to get file attributes present in a Unix server and when I type this url in my IE it displays the files in the file-folder-directory architecture.

I am planning to write a code for a tool such that I can automate the process of getting the file attributes like file modified date,size of file etc.

Are there any Methods/ways to do this? Does this code work:

File file = New File("http://<someserver.com>:<portnumber>/logs/log.txt");
Date date = file.LastModifiedDate();
System.out.println("modifed date is"+date);
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
ManiVI
  • 556
  • 1
  • 5
  • 18
  • Is the unix server available as a mapped drive or only via http? – Jason Nov 11 '10 at 05:41
  • The files in unix server are accessed only via http only..the file name,recently modified date,size are pushed to apache server and displayed in a web application and I can view the files in file-folder-directory format when i enter the url in the IE. – ManiVI Nov 12 '10 at 12:39

2 Answers2

1

If the protocol your server supports is only HTTP, I'm afraid there's no easy way to do this. You will have to:

  • parse the returned HTML, probably looking for <a href= tags (using some html parser, but not with regex)
  • open those links with new URL(url).openConnection(), read their streams, and do the same thing recursively, until an actual file (and not directory) is found.

But this won't give you the file attributes - only the name and the file contents.

If you want to browse, you need a different protocol, like FTP or SCP.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • thank you Bozho :) i will work on this but my main target is on extracting file modification date..:) – ManiVI Nov 12 '10 at 12:36
0

The HTTP protocol won't help you here. HTTP does not publish any file attributes, except for the Content-length (file size) and the Last-Modified header value which doesn't necessarily mirror the actual file modification date. Also it might not be sent by the HTTP Server at all.

Your best bet would be using an FTP library for example the one from Apache Commons Net.

If you decide to use this library, you can use the properties of the FTPFile class, for example the file size, file date and permissions.

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329