GeeCON Prague 2014*
The moose likes Java in General and the fly likes File trasfer between machines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "File trasfer between machines" Watch "File trasfer between machines" New topic
Author

File trasfer between machines

joseph prabhu
Ranch Hand

Joined: Feb 26, 2008
Posts: 162
hello

i need java program to transfer files between two machine.

As a first step i get the list of files in the machine(source).
i create a socket class object like this



it gives following excetion.

java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect

what is the error in Socket class . please help me.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

The other PC should have a server socket listening on that same port, or of course it will fail.

Why not use a known protocol like SMB (also known as Windows sharing, Samba is the Unix / Linux implementation) or FTP?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
joseph prabhu
Ranch Hand

Joined: Feb 26, 2008
Posts: 162
Originally posted by Rob Prime:
The other PC should have a server socket listening on that same port, or of course it will fail.

Why not use a known protocol like SMB (also known as Windows sharing, Samba is the Unix / Linux implementation) or FTP?


hello

i create the ServerSocket class object of constructor


it gives the exception called

java.net.BindException: Cannot assign requested address: JVM_Bind
java.net.BindException: Cannot assign requested address: JVM_Bind

but it does not give the exception for other 2 constructors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

The third parameter to the ServerSocket constructor should be the IP address or hostname of the server itself, in case you have multiple IP addresses or hostnames. In your case you probably won't need that so you can just omit it.

That parameter does NOT indicate the client - servers shouldn't care about who their clients are*, as long as they follow the protocol.


And don't forget to start the server before starting the client


* Of course it's possible to block IP addresses because of security, but that's at a higher level.
joseph prabhu
Ranch Hand

Joined: Feb 26, 2008
Posts: 162
Originally posted by Rob Prime:
The third parameter to the ServerSocket constructor should be the IP address or hostname of the server itself, in case you have multiple IP addresses or hostnames. In your case you probably won't need that so you can just omit it.

That parameter does NOT indicate the client - servers shouldn't care about who their clients are*, as long as they follow the protocol.


And don't forget to start the server before starting the client


* Of course it's possible to block IP addresses because of security, but that's at a higher level.


i am going to develop the one program to copy the files between the machines

not as client or server program. is it correct.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Well, you started using Sockets, so you need some server (ServerSocket) to connect to. That makes this a client-server solution.

Like I asked before,
Originally posted by Rob Prime:
Why not use a known protocol like SMB (also known as Windows sharing, Samba is the Unix / Linux implementation) or FTP?

You can then use the java.io package. You will need a third party library for the FTP part, but Apache Commons Net and JvFTP are great for that.
 
GeeCON Prague 2014
 
subject: File trasfer between machines