how to access directory from file server in java? - java

HI...
Currently I m working in a application in which application allows to access directory (which contains some files) from file server to Application (client).
I tried following code..
URL url=("http://192.168.5.555/file-server/user/images/");
URI uri=url.toURI();
File list[];
list= new File(uri).listFiles();
But its thrown java.lang.IllegalArgumentException Exception.
I don't know how this happen?
I simply access images directory from the given URL (file server).
Help me...

That isn't going to work. The java.io.File operates on the local disk file system only, i.e. on URI's starting with file:// only. It would otherwise indeed going to be too easy to leech files from places where you aren't allowed to do so.
Check if the server in question supports FTP, then you can just use FTPClient#listFiles() for this. If it doesn't, but it supports directory listing, then you need to parse the HTML response containing the directory listing with a HTML parser like Jsoup and then refire a new request on every found link.
If it doesn't support FTP or directory listing, then you're lost and you're probably trying to do bad things.

Related

how list all files from directory in java web application?

I implemented a java web application using html page and servlet classes. In servlet class, I need to read a list of files one by one from a specific directory in the project as follows:
File folder = new File("C:\\Users\\Alahram\\Desktop\\latest RC2\\latest
RC2\\RC2\\src\\docs\\");
File[] files = folder.listFiles();
It works correctly from an absolute path on localhost, but I need to use relative path for this directory to be able upload this project to the server. Can anyone help me in this problem?
The application container (Tomcat, Jetty or any other) started on a specific host cannot access to filesystem of the client of a distinct host that uses it through its browser for obvious physical (a machine don't see the filesystem of the other by default : these are not connected) and security reasons (we would not that either).
To be able to load this directory you should zip it from the client side and then send it via a HTTP request, what we commonly call upload. Then unzip it from the server side.

Loading properties

So i have a file called app.properties which contains to urls in the format of
somethingurl=http://.../.../.../something.js
Note:there is actual url
But i switched to an internet less environment and cannot get the files.
So instead, i replaced the urls with actual paths to the files that i downloaded.
But i get a java.net.MalformedURLException: no protocol. So now i have the files that urls were pointing and i try to use them create an instance of JSFactory.
So is there a way to make the paths work?
I use to jsoup.connect(app.properties.getProperty("...")).ignoreContentTyp(true).execute().body();
Can i still use file: protocol?
Use file protocol. file:///path/to/your/file.js

Java - get real filename of symlink on remote HTTP Server

I am working within Java, and downloading files from a HTTP Server. Now we are working with symlinks here, so we do not need to change the http link - it is always pointing to "last-uploaded.zip" which is linked to the last uploaded zip file, as an example "package43.zip".
Do I have the chance to get the original filename within java? So the link is pointing to "last-uploaded.zip" but if it is downloaded I want to rename it to "package$version.zip".
Regards,
Marco
No. The whole symlink concept doesn't transfer over HTTP, so when you make a HTTP GET for last-uploaded.zip you don't know if it's a file, a symlink or just an endpoint that returns bytes.
The simplest solution is probably opening the zip and searching for the version number from inside there somewhere.

How to get an attached file from document context (handle request for uploaded file) domino

I am new to domino.
I trying to handle a file upload request in Java agent of domino.
I assumed that it should be an embedded object in document context, but it is NOT there.
I don't know any other way, Is there a way to get the file which is sent as a post request? How does the domino handles it.
thanks
The simple solution to uploading files is just to create a Form containing a FileUpload field and then move or process the file in the QuerySave agent. Don't think you can upload files to and web agent.
Good links:
How To: Upload Files To Domino From Flex
Adding Your Own File Uploads to Forms
/Not soo much newb anymore
Most likely the attachment is embedded into a RichText element in the document. To access it, iterate through the document.items and find an item of type RICHTEXT. Then you can check it for embedded objects.
There is a useful domino object map located here
/Newbs

getFilePath API of FilePart not working as expected

I am working on a webbased application with servlets and JSPs in it. My requirement is to get the path of a file which is uploaded in my application.
The legacy code used to get the name of the file by using the code -
//FilePart class of the com.oreilly.servlet.multipart package.//
FilePart filePart = (FilePart) part;
screenosInputFileName = filePart.getFileName();
The getFileName returns the name of the file correctly as a string like "a.txt". Since I want the path also, I am using getFilePath as in--
String path = filePart.getFilePath();
However, I find that getFilePath is only returning the file name and not the file path. That is, getFileName and getFilePath are returning the same value "a.txt". What I was expecting from getFilePath was something like c:\myfiles.
Also, I am running my application in an Ubuntu enviroment (a linux flavour).
Any ideas why getFilePath is retuning only the filename and not the file path ? And how to overcome the problem. Any pointers higly appreciated.
Note: I am not familiar with com.oreilly.servlet.multipart.FilePart.
If FilePart represents the file on the client, then it is impossible to get the path of it (there is no reason for a server to know whether a.txt was uploaded from C:\Users\bob\ or from /home/bob/Documents/, so that information is not included).
If FilePart represents the file on the server (if your server saves uploaded files to a temporary directory so that you may access them as actual files), then you should be able to use this to get the actual path to the file:
String path = new File(filePart.getFilePath()).getAbsolutePath();
I hope this was helpful!
It used to be that Internet Explorer would include the full path of the file on the client's computer. I don't know if it does that anymore, but i don't think so, because it's a privacy issue. The server has no business knowing the full path.
getFilePath is only going to work if the client is using Internet Explorer, as it's the only browser that returns the entire file path to the server. Chances are, it'll only work with IE6 at that, as I believe MS finally realized this wasn't a good security practice when IE7 came out.

Categories