Results 1 to 5 of 5
  1. #1
    phani is offline Member
    Join Date
    Apr 2008
    Rep Power

    Default To transfer a file from client to server

    I am new to Java and would like to know how to transfer a file from cclient to server.I need to transfer the whole file and not the contents. Like I might need to transfer an .xls file to server and can open it

  2. #2
    dream_noir is offline Member
    Join Date
    Apr 2008
    Rep Power


    There are lots of ways to transfer a file from a client to a server and depending on the purpose and what your working with you can probably narrow it down to what suits you best..

    Are you writing both the client and server software? If you are, you can do it however you like, if not you'll have to find out what protocols the application your trying to send/get a file from uses and use that.

    Obviously you'll have to send it over the network, if your writing both the client and server and what to do all the dirty work yourself you should look at Sockets. There is a tutorial on the java website. Basically all you have to do is make a TCP connection between the client and server (using Sockets). You can then either come up with your own protocol or implement a protocol meant for transfering files, like FTP.

    If you just had to send one file a simple protocol could be something like this:

    Client: connect to server and say "hello"
    Server: respond with "hello"
    Client: sends filename to be sent
    Server: responds "okay filename" or maybe "no filename" if it won't accept it
    Client: opens a filestream of some sort and sends the file bit by bit.
    Server: after file succesfully saved says "received filename"
    Client: "good quitting"
    Server: "quitting"

    You could make it even simpler than that, but that is the basics.

    If you don't want to have to deal with that or your interfacing with an FTP server you didn't write on one end. There are some implementations your free to use in Java at this link: Java FTP Tips

    I'd take a look at that page, the java page on Sockets, and lookup some basic information on TCP (transmission control protocol) so you can figure out what is going to best suite your needs.
    Last edited by dream_noir; 04-16-2008 at 05:35 PM.

  3. #3
    kibur is offline Member
    Join Date
    Dec 2009
    Rep Power


    How are u all?
    I want to write a client and server side code which will transfer file from client to server. How I can code it?

  4. #4
    skyebase is offline Member
    Join Date
    Apr 2010
    Rep Power


    i am writing a java application to copy files over sockets . the file got copied but when i tried openning the file, the file was damaged in transit.please can any one help me out wat is going on please

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. send file via client - server model
    By spasavvas in forum Networking
    Replies: 15
    Last Post: 08-13-2010, 12:45 PM
  2. Replies: 2
    Last Post: 10-05-2008, 07:13 PM
  3. how client know what kind of server
    By lemur in forum Networking
    Replies: 3
    Last Post: 05-31-2008, 08:11 AM
  4. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 10:18 AM
  5. Problems with client and server
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts