I have a java application that, at some stage, select files from the local filesystem using JFileChooser.showOpenDialog().
Now I want it in a client-server setup. This means opening a GUI(file browser) for selecting files on the server. I have already tried several scenarios to keep using the JFileChooser, but I cant get the correct setup working.
Does anyone know how to construct a file browser on the remote server if i know the path the file browser needs to default to in advance?
So for eg: if the server address is "http://sand.int.group.com:9083" and on this address the directory that i want to default to is at "/home/myDir/". How can I display the file browser window so that it lists the files located in the directory on this server?
JFileChooser can't load a URL. You will need to map a network share on the machine that wants to browse to the files.
This will serve you purpose, I believe: http://vfsjfilechooser.sourceforge.net/index.html
A remote file chooser based on JFileChooser code...
AFAIK this is not working out of the box. The local JFileChooser has no idea about files located on server side.
Take WebSphere for example, with the Websphere admin tool you can deploy local EAR/WAR files to the server, IBM is doing this with a JFileChooser. But when you are going to deploy a file which is on the remote server you get a completely different UI. So it seems to be very tricky.
One possible way might be to implement your own FileSystemView, but I am not sure, this is just an idea.
Related
I am working on a feature where i have to provide a direct link to download certain files. all my files are in htdocs folder and i want to provide a direct link to download them like
webapp.com/files/file1.avi
could write a servlet and send the user a file.I know how to do it.
The other way is that if i directly go to webapp.com/files i should be able to see all of the files present in the directory. How do i do that?
do i have to make any server config changes to achieve it?
the webapp is running on Apache tomcat and jdk 1.4
You can directly serve your static content from tomcat(if it is your app server) root directory. I assume other app/web servers will have a static content directory as well.
I wrote a RESTful web service using Jersey library and in order to respond to the request I have to read a text file in local file system. C:\data.txt. The servlet works fine when I run it with tomcat on my own laptop.
But when I deploy the war on another machine running windows server OS and place the data.txt again at C:\data.txt. The servlet can't locate the file correctly. Anyone has idea about why is this?
Thanks a lot!
Check whether the Tomcat server process has read-access rights to file C:\data.txt. Check which user is used for running the tomcat process and check the corresponding user file permissions.
I also suspect it is a security error. Applications are usually restricted to reading and writing within their own directory under $TOMCAT_HOME/webapps. If this is the case, you need to change $TOMCAT_HOME/conf/catalina.policy to allow you to access other directories.
If you don't need to write to the file, consider moving its location inside of the classpath by putting in into $TOMCAT_HOME/lib instead.
I think this approach is also better in regards to being cross-platform.
I'm working on a jsf2 web application and i need to upload files to a folder in my webcontent and keep them permanently, I used the technique that is mentioned in JSF FileUpload Directory and i could upload to wtp... folder's subfolder, but as BlueC said it get lost when tomcat restarts, is there any way to do that?
You can store the files in a Database using a BLOB field. It will depends of how you are implementing the persistence layer of your application but in the Java side usually you will implement this field as byte[]. So it will be comfortable for download or display the file.
You can upload the files to a certain directory/ default directory and then manually copy the files to a secured folder that is outside of the deployment directory and application server installation (yes you can do that).
I have 2 application deployed on my server and first application is suppose to list the files in a folder in another application.
But the problem is these two application may be deployed on 2 different physical servers. So is it possible to fetch the files from the URL
i.e is there a way something like
List<file> getFileList(<URL>/folderName) ;
That's not possible by HTTP. Use FTP or let the server platform mount it on the local disk file system.
As #BalusC said, by HTTP it is not possible... unless you write a special script of your own returning a list of files in the folder you need (with permissions check, of course).
In our Java web application, customer wants to upload some large files to a SFTP server and download directly from there. The customers do not want to use any third party tool rather they want this functionality in the application itself.
The file upload part has been taken care of by the JFileUpload applet component & libraries. Once the file gets uploaded I could figure out the exact location of the stored file. And that uploaded file will be shown to the users as a link which they will click to download (like an HTTP or FTP file link).
So I've to decide the strategy for downloading the file from the SFTP servers.
One option is to parse the request, then connect with the SFTP server and stream the file via HTTP server. But here the file will be downloaded over HTTP rather SFTP and moreover it will not serve the purpose of using SFTP.
Another option which I could think of is via an applet, again like upload. As soon as the request for the SFTP file comes to the HTTP server, it will launch a page containing an applet having a directory browser for users to decide the save path. Once the user selects the save location, the file will automatically start downloading to that location from the SFTP server. In this way the connection will be completely SFTP.
I want to know how much feasible the second approach is and if there are any important things I'll have to take care of. Which SFTP libraries are the best to use for this type of operations?
Moreover, please let me know if there are other better options to do mentioned activity.
Edit
It seems this post looks like a request for suggestion on ways to download from SFTP server (may be from the heading but I could not think of any other heading!!). Thank you for the suggestions on the APIs to do that but the more important issue for us is to figure out a way where a user's request to download a file from SFTP server is done over secure SSH rather than over HTTP. Now using the mentioned APIs we could very well download the files from the SFTP server to the HTTP server's filesystem but after that if we have to redirect the same file to the user's machine we have to use HTTP and that is what we want to avoid.
Our second thought approach of using a page with an applet which will initiate a SFTP session between user's client and SFTP server is to address the above concern.
How difficult will it be to implement and what should be our approach in this regard?
And if there is any other better & easier way to do the same task then please suggest.
I favor Commons-VFS for this kind of thing. It abstracts out the actual file system type and lets you work with a standard interface regardless of the underlying implementation. It in turn depends on other libraries for the actual systems, in particular JScsh for SFTP.
I recommend using JSch, Java Secure Channel. It is a pure Java implementation of SSH2. It has good examples for doing SFTP in addition to pretty much every other SSH2 option (XForwarding, port forwarding, etc.). We use it in a number of our projects, and have not had any issues. I have even tied it's GSS-API (Kerberos) support into a native Kerberos implementation and it worked well. It is BSD licensed, so commercial or not, you shouldn't have much issues with licensing.
I see building an applet using JSch to be pretty simple. Biggest issue will be to make sure your applet is signed and has permissions to write/read local files and connect to the SSH servers in question.
The customer is always right, so while the requirement screams bad architecture to me, I'll just extend my sympathy on that and try to help you with the problem.
The applet approach is OK, but seems kind of clunky for a web app. There are javascript sftp libraries out there. This one supports sftp and will give a much more natural feel to a web application than poping up an applet just for the sake of providing a file transfer. It isn't free, but it isn't that pricy either. It still uses an applet under the hood to effect the file transfer, it just doesn't present a java screen to the user.
Did you mean SFTP or FTPS (FTP over SSL)?
If you realy ment SFTP, have a look here: http://www.spindriftpages.net/blog/dave/2007/11/27/sshtools-j2ssh-java-sshsftp-library/comment-page-1/