The java.io.File class won't let you read or write files on some other
remote machine, e.g. Applets can't read or write files on the server,
even if they are signed. The File class in an application may let you read or
write files on some other machine on a LAN, but that depends on the underlying
operating system to make the files on the other workstations on the LAN look
those files like local files. It won't do you any good to concoct filenames that
look like URLs. The File class is only for reading
local files!
But why? Why can't you just use an URL as your filename, and read and write
files on some remote machine? The problem is you don't want people out on the
Internet reading and writing your files, or files on your server, without
monitoring very carefully just what they are doing. You don't want to give any
old Tom, Dick or Harriet out on the Internet the keys to read or write any file
on your system whenever they want.
Unfortunately, the Java file system has no security features. There is no
way to identify yourself, to prove your identity, or to limit your read/write
access to a given set of files or directories. It presumes unlimited read/write
access. This is just not good enough for remotely reading and writing files.
Servers typically don't provide a means for remote machines to directly read or
write their files. When they do, such as in Novell NFS servers, there is a whole
layer of security tacked on top.
Instead, servers provide a pot pourri of indirect ways to read and write the
remote files. In each case you run some program on the server that talks via the
Internet to the remote computer, and does any file reading and writing on its
behalf. e.g.
-
Canadian Mind Products FileTransfer
classes let you copy files from a variety of sources, including jars, to a
variety of targets, both remote and local. They use HTTP protocol where
necessary.
-
CGI (Common Gateway Interface) lets
you communicate with a servlets running on the server
that will read or write files for you and send back results. See Base64
to convery your binary data to only printable characters.
-
HTTP (Hypertext Transfer Protocol)
HTTP GET allows reading of a selected set of files, HTTP POST lets you send a
query and get back information. HTTP PUT lets you upload a file, though the PUT
feature is rarely supported.
-
JDBC (Java DataBase Connectivity)
lets you communicate with an SQL server running on the server to read and write
database files.
-
Sockets let you send raw streams of bytes back and
forth between remote machine and server. The program on the server can then use
that information to read and write files. If you compress your data, this about
as efficient as it gets.
-
RMI (Remote Method Invocation) lets
you send Java objects back and forth between the remote computer and a server.
Each can run methods on the other published objects. These methods may read and
write files.
-
EJB (Enterprise Java Beans) are like RMI
plus servlets, plus transaction logging and backout.
-
FTP (File Transfer Protocol) allows
file upload/download. For efficiency, send only zipped files, bundling many
small files into one big one. FTP is a slower protocol than HTTP but supports
recovery there is a disconnect in mid transfer.
-
CORBA (Common Object Request Broker
Architecture) is like a heavy duty RMI that supports languages other than
Java. It is considerably more complicated to use.
-
Jini. I'm told you can use this for intermachine
communication, but I have never tried it.
-
JavaSpaces. I'm told you can use this for
intermachine communication, but I have never tried it.
Each of these schemes has is own built-in security to be sure the general public
can only see the files you want them too, and that authorised users can only
indirectly read and write the files you want them too.
 | Java P2P Unleashed: With JXTA, Web Services, XML, Jini, JavaSpaces, and J2EE |
| 0-672-32399-0 |
| Robert Flenner, Michael Abbott, Toufic Boubez, Frank Cohen, Navaneeth Krishnan, Alan Moffet, Rajam Ramamurti, Bilal Siddiqui, Frank Sommers |
| Covers a variety of the more exotic techniques for inter-computer communication with Java. |
|
|