ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi there
I was wondering how is it possible for a Server to send a folder with lets say text files to a Client. How can we copy a folder and its contents and sending it as bytes to a client.
Assuming that you know how to send files over the sockets, sending a folder should be almost similar to sending files.
As I see it, a folder is just a container to hold files and the *real* data lies in the files which it contains. So there are two things which you need to do:
1) Recursively traverse the contents of the folder and send the files.
2) Figure out a mechanism where the sender can somehow communicate the folder hierarchy to the receiver, so that it can create the same hierarchy at its end.
A thought: it might be easiest to gzip up the directory structure you want at the sender, and unpack it at the receiver. Java has ZIP helper classes (look in java.util.zip). It solves the problem of how to communicate the directory hierarchy, though you still have to traverse the tree of files to create the archive, unless you cheat and run a gzip command outside your Java program. :-)
A thought: it might be easiest to gzip up the directory structure you want at the sender, and unpack it at the receiver. Java has ZIP helper classes (look in java.util.zip). It solves the problem of how to communicate the directory hierarchy, though you still have to traverse the tree of files to create the archive, unless you cheat and run a gzip command outside your Java program. :-)
HTH,
-nick
This is a good idea to use the java.util.zip class for zipping the folder. However, depending on System to get the gzip tool to actually zipping the directory may not be suitable (a user may not have gzip tool installed, i.e. it doesn't come with all OS, specifically win32 versions).
You could also use jar utility of java to jar the contents (since its natively installed once you have jre installed in your system). Its almost as tar, with j prefix.
I guess you should now have enough options to choose from.
Happy java-(ing)!!!
A great book on JAVA network programming and ressources..
An Introduction to Network Programming with Java
Jan Graba
ISBN 0 321 11614 3
Is actually a very good read - The site below also has the java examples from the book. [EDIT: They have password locked the resources - Didn't use to be that way as far as I remember]
This is a good idea to use the java.util.zip class for zipping the folder. However, depending on System to get the gzip tool to actually zipping the directory may not be suitable (a user may not have gzip tool installed, i.e. it doesn't come with all OS, specifically win32 versions).
You could also use jar utility of java to jar the contents (since its natively installed once you have jre installed in your system). Its almost as tar, with j prefix.
I guess you should now have enough options to choose from.
Happy java-(ing)!!!
I also like the idea of compressing the folder and then sending it as one file over the network. I dont see compression as an overhead here because the data needs to be send over the network, where sending raw uncompressed data can be *far* more costly than locally compressing the data.
I also like the idea of compressing the folder and then sending it as one file over the network. I dont see compression as an overhead here because the data needs to be send over the network, where sending raw uncompressed data can be *far* more costly than locally compressing the data.
Is it possible for you to later share the class you will code to compress and transfer the data? I was working on something like this few months back on C#. Didn't finish it though.
Is it possible for you to later share the class you will code to compress and transfer the data? I was working on something like this few months back on C#. Didn't finish it though.
Although manolakis is actually trying to do this, but if I get the chance I may try it out.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.