Click to See Complete Forum and Search --> : Transferring files form a server


bandaru.suresh
September 29th, 1999, 09:33 AM
Well, I have java application ,which needs to access file on the server and read it and copy it to yet another place.

I have created a socket on client and server socket on the server. The server socket is listening to my client and it is responding each time my client tries to reach it.

Now in io we have FileInputstream which takes a File object. and we can copy one file from another using FIs nad FOS. inthe same m/c.

The Socket class has a method which is returning a InputStream and OutputStream objects. So it means it is only these two which should be used tooacces a file.

As I cannot get a FileInputStream or FOS object , how am I going to acces a file on a remote m/c copy it and save it some where else?

Help would be greartly appreciated
Suresh

DHunter21
September 29th, 1999, 03:20 PM
I'm pretty new to java, but I've just written routines that pass objects through sockets between client and server. My first question is Are you encapsulating the streams properly? Using Objects, I use :
ObjectOutputStream out = new ObjectOutputStream(new DataOutputStream(new BufferedOutputStream(client.getOutputStream() ))));
ObjectInputStream out = new ObjectInputStream(new DataInputStream(new BufferedInputStream(client.getInputStream() ))));

I haven't tried, but I don't see why it wouldn't work to just change the ObjectOutputStream to FileOutputStream. Or maybe you have to encapsulate FileOutputStream with ObjectOutputStream... (ie ObjectOutputStream(new FileOutputStream(.... )) )

It would help to see some code.

Dustin

bandaru.suresh
September 29th, 1999, 03:36 PM
Thanx Dustin for your interest.
Yeah I have not encpsulated the FileInput and Output streams properly.

Suresh

bandaru.suresh
October 7th, 1999, 12:45 PM
Hai Dustin,
I have tried your suggestion it works !!
But is it necesary for the Server Socket to listen to the socket all the time to do a tranfer.?? Is it just not possible that only one program reads a file and sends it to other location and saves it ?

Suresh

bandaru.suresh
October 7th, 1999, 01:36 PM
Hai Dustin,
I have tried your suggestion it works !!
But is it necesary for the Server Socket to listen to the socket all the time to do a tranfer.?? Is it just not possible that only one program reads a file and sends it to other location and saves it ?

Suresh

DHunter21
October 7th, 1999, 06:05 PM
If I'm understanding what your asking: Short answer yes.

If you happen to know exactly when a file needs to be transferred, then you can start the Server Socket, open a client Socket, send the File and close everything. The other way I can see around this (and there could be many way around it that I don't know about) is to send a flag to the server to start the Server Socket. Maybe the client sends a flag through a HTML command, and then the Server knows when to start... but the question is why would you want to do all this extra work? Why when its so easy to open a ServerSocket and leave it open until the application ends. There are something like 64 thousand sockets that could be potentially opened at one time, so the number open shouldn't be a problem (unless your tight on resources).

You could set it up so that once the Server accepts a client on that Socket, that it will not accept any more there after, thus only allowing a point-to-point file transfer system.

I don't fully understand what your trying to produce...

Hope this helps

Dustin

bandaru.suresh
October 7th, 1999, 08:01 PM
Hai Dustin,
Well, my need of transferring the files is continous.Probably for every two hours. Every 2 hrs. till my company closes down.
I was thinking in such a scenario will it be okay to keep a server socket live for time immemorail. But i guess , as you have rightly pointed out there can be 64000 socktes which can be potentially opened at any time and that shou;d take care of anyother needs.
Thank you for your suggestion
Suresh

DHunter21
October 8th, 1999, 11:00 AM
One more thing, just make sure that the socket you choose isn't a socket that another application is likely to use as well. The first 1024 sockets are kind of reserved for system use, and 8080 is taken as well. There's plenty to choose from, but stay away from those.

Dustin