• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help to write Client/Server java socket program to transfer files between client/server

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to write a client/server socket java program to simulate FTP to transfer file between client and server.
Basically, the program performs 3 commands: put: upload files to server, get: downloads files from server,change:change files name resides in server.
the program is running on two local machine(client and sever) by command line input.
Appreciate any help or resource,

Thanks so much!
peter
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to define a protocol for this: the client sends a request, and the server sends a response.

If you don't mind limiting the protocol to Java you could send objects, and wrap the Socket's streams into ObjectInputStream and ObjectOutputStream. You then send a Request object, and wait until the server sends a Response object. You can use one interface for Request with multiple implementations (one for each request type), and one interface for Response with multiple implementations (one for each response type).

If you want to make it more general you will need to go through a bit more trouble. A very simple example for download:
- "download <file>" is sent to the server
- the server sends back the number of bytes to send, followed by the file's bytes. The number is used to determine how many bytes to read, since the stream will not be closed afterwards; you will reuse it for other requests.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic