Click to See Complete Forum and Search --> : get server file system
Nicole
September 15th, 2000, 05:01 PM
Hi, there,
when I try to access a file on Server side from An Applet, I can use URL, for example, "http://1.1.1.1/some/some.gif", which has to be an exact file name. If I want to get the file system structure, for example, if I want to check how many files are in "http://1.1.1.1/some" directory, how can I do it?
When I try to use File class, it always gave me security warnning.
Help !!! Thanks in advance.
Yours Nicole
Norm
September 17th, 2000, 11:03 AM
To see anything on the server requires that the server give it to you. For example when you use a URL or URLConnection, you are using the HTTP GET method to ask for the file. So if your server has a command that will return a list of files, use that. For example FTP has a command that will request the server to return a files list.
Nicole
September 18th, 2000, 05:31 PM
Thanks, dear,
I am still not clear about your comments. At present, I use IIS4.0 as web server.
Would you please send me some sample code,or give me other reference article. Thanks again.
yours Nicole
Nicole
September 18th, 2000, 05:42 PM
Hi, there,
When I wrote the following code in an Applet,
..................
URL url = new URL(getCodeBase()+"WorkInProgress/test1/");
File file = new File(url.toString());
File[] children = file.listFiles ();
..................
And when I run it in IE5, it always gives me the following error message:
---------------------------------
JAR cache enabled.
Opening http://64.16.6.114/ebiz/ADemo/testFile/testFile.class with cookie "ebizIntranet=USERID=Mark+Holman".
java.security.AccessControlException: access denied (java.io.FilePermission http:\64.16.6.114\ebiz\ADemo\WorkInProgress\test1 read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.list(Unknown Source)
at java.io.File.listFiles(Unknown Source)
at testFile.testFile.jbInit(testFile.java:32)
at testFile.testFile.init(testFile.java:20)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
-----------------------------------
But, if I call file.getParent() method, it works well in Browser, and shows the correct parent directory.
Would you please give me some instruction.
Thanks.
yours Nicole
Norm
September 19th, 2000, 09:19 AM
The File class does Not read data from a server. It's only for local files. I don't think the use of the URL class in your code is correct. Your program is only reading data from the local computer.
To read anything from a server requires that the server be able to receive commands and respond to them. For example the FTP protocol has commands for the client to ask the server for a directory listing and many other file management commands such as deleting and renaming files. Each server can have different protocols that it responds to.
Nicole
September 19th, 2000, 11:03 AM
Thanks, Norm,
Would you please give me some sample to use Java access Server File System with FTP protocal? I don't know how to write this kind of code.
Thanks again.
yours Nicole
Norm
September 19th, 2000, 02:29 PM
I'm sorry, I don't have a code sample using FTP. FTP is normally used manually from a DOS console. It's an old protocol that has been in use for a long time. The protocol is documented in a RFC, but I don't know the number. There has been another question on the forum about using FTP. It's not a simple 3 lines of code thing.
And not all servers have an FTP server.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.