I need to create a list of links on my JSP, related to some files that are in a specific folder (with html extension), on a Unix server.
My questions are:
How do I "connect" to the Unix server? My JSP will be stored on the same server that I need to search into.
What method I should use to search through my specific folder?
You can use the File.listFiles(...) method (on any OS/filesystem actually). Be aware that there might be limitations if the uid for webserver has no access to the folder/files or is eg. in a chroot'ed environment on the UNIX box.
The following code snippet
File[] files = new File( "/your/folder" ).listFiles( "*.html" );
should give you a File[] array with the files satisfying the .html condition in /your/folder.
Cheers,
You could do this in several ways.
If the share on the server is local or locally mounted already, then you can use Anders R.Bystrups answer.
If it is not, then you need some method of connecting to the server.
If it is a shared resource (a shared folder, for example), then you can access it with //server/share/file).
If the server is running FTP or SFTP, then you can use the relevant service to retrieve the list of files.
Finally, the server could run a web service (which you would have to write) which could expose the list of files it has.
Related
I want to access a file server that is not present in my network, but I have credentials of other domain that can be used to access the file.
How do I gain access to the file in share?
Is it possible to gain access to the file using a java program?
Operating System is Windows. I want to read the contents from .txt and .csv files present in the share and display it on a web page.
I used jcifs library to solve this. It works great.
You can use ftp protocol.
And also can make a map drive from share folder on your system. It's a simple solution.
I'm currently developing a Tracking System with JavaFX and MySQL as database that is kept in a server. My application is used within a network and allows users to upload and download pictures and several types of document.
My question: What is the best way to send and retrieve files to a server within a network? And should I store those files in MySQL or just their paths in MySQL? If only files' paths, do I need FTP or other techniques? I need detail answer because it is my first time to develop such application.
Edit: I want to store data in a server. I build this application for client machines so that clients can keep documents in the server and they can access their files from any machines... I have no idea for how to transfer files from client machines to server. Please help me!
You should use socket programming like what is at following link:
http://www.rgagnon.com/javadetails/java-0542.html
.But if you are using Java7, Files is the best one instead of BufferedInputStream or FileInputStream (No extra library require):
/* You can get Path from file also: file.toPath() */
Files.copy(InputStream in, Path target)
Files.copy(Path source, OutputStream out)
I have developed a website, one of its operation is to read and write data to text files stored at my local machine such as D://test.txt or C://file.txt, but now I am going to host my website at the external server, i mean over the internet use, i wonder where to keep these files that are associated with read and writing operations. At present I am getting an exception file not found if i am using my local machine location. For your information, I am using GlassFish server.
You will want to create a system property on Glassfish, which represents the file path and name. Then upload the file to that location of your choosing on the server where your website application is deployed.
Depending upon your needs, you may find it easier to deploy the file out with your application. Make sure the file is on the classpath, and you can load it using any number of ways.
How to list all the available shared folders under a specific IP Address?
Mock code:
IP ip = new IP("10.0.0.9");
for(File share : ip.getSharedFolders){
System.out.println(share.getName());
}
Is there a way in which this can be accomplished?
I want to make something similar to windows network explorer and I need to get all the shared folders under a specific IP so I can ggenerate a tree.
With the first level shared folders I can easely get the lower levels like this
for(File f : new File("//10.0.0.9/d").listFiles()){
System.out.println(f.getName());
You can get the list of shares using the The Java CIFS Client Library and in particular the SmbFile.list method. Here is a small illustration of how to use this API:
SmbFile server = new SmbFile("smb://server/");
String[] shares = server.list();
Java from out of the box does not support what you are trying to do.
You need to use libraries such as JCIFS to do this.
One easy/cludgy way out though would be to make sure that you have a drive mapping ( if windows or nfs/smb mount for other OSs) to the location and then treat it as a local file - using java.io APIs.
If the files are accessible through the server IP address (network wise and permission wise) then sure you can list them all recursively by doing the following:
Get the remote folder name. Example "//10.0.0.9/folder"
Iterate through that folder just as you would do to list files in a local directory (see this link to know more about listing local files in a local directory
We have a web application that allows user to download a zip file from a web server. We just provide dummy iframe source to the full URL of zip file on web server. This approach would allow end user to use browser controls which allows the user to open or save the zip to user's local machine.
We have a requirement that the zip file is automatically extracted and save to a specific location on user's machine. Any thoughts on how this can be achieved?
Thanks.
I highly doubt that you'll be able to do that. The closest you're likely to get is to generate a self-extracting executable file (which would be OS-dependent, of course).
I certainly wouldn't want a zip file to be automatically extracted - and I wouldn't want my browser to be able to force that decision upon me.
Short answer is I don't believe this is possible using the simple URL link you've implemented.
Fundamentally the problem you have is that you have no control over what the user does on their end, since you've ceded control to the browser.
If you do want to do this, then you'll need some client-side code that downloads the zipfile and unzips it.
I suspect Java is the way to go for this - Javascript and Flash both have problems writing files to the local drive. Of course if you want to be Windows only then a COM object could work.
Instead of sending a zip file why don't u instruct the web server to compress all the web traffic and just send the files directly?
See http://articles.sitepoint.com/article/web-output-mod_gzip-apache# for example.