This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Browse a folder on server. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Browse a folder on server." Watch "Browse a folder on server." New topic
Author

Browse a folder on server.

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Normally, when we upload a file there is client-side handy,


that helps in selecting the file to upload.

But I want to make a choice on the server also. I am ready to have a folder within my web-app itself say like "uploads" and subfolders like "document", "pictures", "songs" etc. or whatever else. My user should be able to select this folder and dump the file there, if needed he should be able to create a new folder. How do I go about it? There are two thing that worry me, first the recursive iteration part and second rendering the datastrcture to client & reconstructing it back in terms of HTML/javascript. I do not want to have applet on the page.
Any suggestions please.



Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41178
    
  45
Why would the user care where a file is stored on the server? That's an implementation detail that should be hidden from her. It's up to the web app to store and organize the files in a way so that they can be found and retrieved later as needed.


Ping & DNS - my free Android networking tools app
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Thanks ulf. I have to share information with the user because he is not the final end-user rather a middle man. He works on my web-app, the web-app has a WYSIWYG editor and the user designs and builds on static content with it, what he creates and builds I am not bothered but content will be redeployed further (again through the web-app), and I have to make it all convenient for him. It thus tends to bend more at sharing half-transparency with this middleman so that he can be at ease on building and organizing his static htmls.

May be as you said I can hide implementation detalis from him but I would atleast have to fake him with some gui that looks and works like the way he expect it to, the ability to create directories and work around them, he would expect that his relative-links map on the directories he creates and files he uploads. I can have everything uploaded to single directory and have some indexing information but that would again complicate my job when i deploy it all. So I *have* to keep some information shared and that *only* some information remains shared.

I think of JTree but that is swings way. Any other option would be welcome.
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
Hi Akhilesh..,

I had infact encountered the same kind of problem sometime back in one of my projects.
The solution, which I made during that time was to build a javascript based tree [or Ajax, upto you to decide..]
to display the server folder structure on JSP [view layer], and then use one of the SCP libraries [Trilead has a good one, open source and free too] to browse folders on a unix/linux based server. On windows servers, you just need to enable "share" permissions on the repository you need to browse, and then you can directly use the java.io.* package to browse through those directories.

I'm not sure if this is a politically correct and right solution, but it never failed me till date. Hope this helps.

Dawn.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Thank you very much Dawn. This should be enough to go on. Hope it doesn't fail with me too. ;-)
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
Anytime, mate... by the way, I made a mistake in my previous post, it is not SCP library, but SSH library.
You may search for trilead-ssh or jsch, two of the free ware open source ssh libraries I compared during my problem stage... (finally settled for trilead, since it had SCP capabilities too, which I required..)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I installed an FTP server to handle this sort of thing. I used the FileZilla open source server.

With careful attention to setting user privileges it gives you very detailed control over what a client is permitted to do.

There is also a FileZilla client package but I have not used it.

Bill
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Dawn Charangat wrote:Anytime, mate... by the way, I made a mistake in my previous post, it is not SCP library, but SSH library.
You may search for trilead-ssh or jsch, two of the free ware open source ssh libraries I compared during my problem stage... (finally settled for trilead, since it had SCP capabilities too, which I required..)



I had googled for 'scp library trilead' and had reached probably at the right place "Trilead SSH for Java". There was a big button "Buy Now" at the very bottom which made me think, I soon clicked "license" tab and it made me sigh for while, and then done with 'download'. Exploring with examples and apis at the moment will sure get back in case trouble. Thanks again.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
William Brogden wrote:I installed an FTP server to handle this sort of thing. I used the FileZilla open source server.

With careful attention to setting user privileges it gives you very detailed control over what a client is permitted to do.

There is also a FileZilla client package but I have not used it.

Bill


That's another good option Bill, at the moment my worry is to have a directory structure delivered on the browser. May be at later stage this could be on focus, by the way how did you connect to server without FileZilla client, are there FileZilla client libraries available in java?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
how did you connect to server without FileZilla client,


There are numerous FTP clients, commercial and open source. I use CuteFTP, I'm not sure what my clients were using - FTP is very well standardized. A google search for java ftp client will get you an astonishing assortement of possibilities.

Bill


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41178
    
  45
Now I'm curious: The initial question was about a web app that handles server-side files, and how to present those to a user. How do FTP, FileZilla and SSH fit into that? Is there something else happening on the server that makes use of those, or will the user be expected to use any of these?
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
Hi Ulf... As I mentioned in my previous post, I'm not sure if this is the *right* way of doing it, but for me, I had to present the server side file list to the user, and for that, in case of a unix server, I had to establish an ssh session, get the list of files, and display it off... its for that, I made use of the ssh library... and for the windows case, once you share a folder, with adequate permissions, you can directly access it from a java program using the java.io package. Hope this clears your doubt.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Ulf your guess was right, i was more concerned over presentation of the directory structure. But when a suggestion from Dawn came, 'trilead'was something new, it made me re-think about server-side on even wider basis.

I have to have one folder shared with the user. There are *not* too many type of users associated, but just one, so i don't have to create separate directory for each user, not so, rather only one directory alone would suffice. Within this directory, the user should be able to create-subdirectories, upload files and/or delete them. However he should not be able to delete this parent directory.

I feel it is Ok to have such a directory within my web-app itself, but the concern is if the amount of upload goes high at later stage, will it add to the performance of the app-server? I believe yes, and it is better that i share this directory outside web-app or even better park it somewhere outside the app-server itself. I think i would not need an ssh thing upto the time i am within web-app, but the moment i am out of my app-server I would need some trusty thing. Coming to ftp, not at the moment, but later we would be archieving the uploads and I guess, this option should fit in that context. We still have to decide on how archieving has to be carried on, whether manual or automatic.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Browse a folder on server.
 
Similar Threads
Uploading
exe file in server side
Uploading
File upload with struts
refresh onload