473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

File copy over Network.

dmjpro
2,476 2GB
HI i am starting Java Networking programming with File Copy over Network.
I got a sample code .... but still having some confusions.

Expand|Select|Wrap|Line Numbers
  1. Socket socket = new Socket(ip,port);
  2. OutputStream out = socket.getOutputStream();
  3. out.write(""); //Where it writes to the destined HOST?
  4.  
Please help me.
Can't I give a particular location in destined HOST?

Debasis Jana
Mar 7 '08 #1
9 9668
JosAH
11,448 Expert 8TB
HI i am starting Java Networking programming with File Copy over Network.
I got a sample code .... but still having some confusions.

Expand|Select|Wrap|Line Numbers
  1. Socket socket = new Socket(ip,port);
  2. OutputStream out = socket.getOutputStream();
  3. out.write(""); //Where it writes to the destined HOST?
  4.  
Please help me.
Can't I give a particular location in destined HOST?

Debasis Jana
w.r.t. your question at line 3 of your code: yes it writes to the host located at
IP address 'ip'; the host listens to port 'port'. The host should open an InputStream
and read the data stream; the input comes from the client. The host is free to do
anything it wants with the data, so it can also create a file and write the data it
received to the file. As far as that server is concerned it reads bytes from a stream
and does something with it. As far as the client is concerned, it writes bytes to
that output stream to the server.

To answer your last question: yes the client can also write the name of the file
to that output stream. You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes.

kind regards,

Jos
Mar 7 '08 #2
dmjpro
2,476 2GB
w.r.t. your question at line 3 of your code: yes it writes to the host located at
IP address 'ip'; the host listens to port 'port'. The host should open an InputStream
and read the data stream; the input comes from the client. The host is free to do
anything it wants with the data, so it can also create a file and write the data it
received to the file. As far as that server is concerned it reads bytes from a stream
and does something with it. As far as the client is concerned, it writes bytes to
that output stream to the server.

To answer your last question: yes the client can also write the name of the file
to that output stream. You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes.

kind regards,

Jos

If I want to copy to that destined machine+particular directory then what should I do ....means what should I give ...as HOST NAME and PORT????
I am getting a connection refused Exception ....

Please Help!
Mar 8 '08 #3
dmjpro
2,476 2GB
If I want to copy to that destined machine+particular directory then what should I do ....means what should I give ...as HOST NAME and PORT????
I am getting a connection refused Exception ....

Please Help!
Jos I need a help here!
Actually when I copy the file over Network there should be username and password of where to be copied.
That's where should I me mention??
And the particular location that where should I mention??
Please Help.

I run a code in my Machine.

Expand|Select|Wrap|Line Numbers
  1. package networking;
  2.  
  3. import java.net.*;
  4. import java.io.*;
  5.  
  6.  
  7. public class lookForPorts {
  8.  
  9.   public static void main(String[] args) throws Exception{
  10.  
  11.     Socket theSocket;
  12.     //String host = "localhost";
  13.     String host = InetAddress.getByName("10.29.32.68").getHostName();
  14.  
  15.     if (args.length > 0) {
  16.       host = args[0];
  17.     }
  18.     for (int i = 0; i < 1024; i++) {
  19.         System.out.println("DMJPRO: =============== " + i);
  20.       try {
  21.         theSocket = new Socket(host, i);
  22.         System.out.println("There is a server on port " + i + " of " + host);
  23.       }
  24.       catch (UnknownHostException e) {
  25.         System.err.println(e);
  26.         break;
  27.       }
  28.       catch (IOException e) {
  29.         // must not be a server on this port
  30.       }
  31.     } // end for
  32.  
  33.   }  // end main
  34.  
  35. }  // end look for ports
  36.  
Here only three ports I getting where I can connect.
So which port I should use here.
I am getting confused.

Debasis Jana!
Mar 8 '08 #4
dmjpro
2,476 2GB
One more thing JOS!
Could you explain "You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes."????
How should I define a Protocol?

Debasis Jana
Mar 8 '08 #5
JosAH
11,448 Expert 8TB
One more thing JOS!
Could you explain "You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes."????
How should I define a Protocol?

Debasis Jana
If a client wants to use a service it has to know the ip number of the host that
runs the service *and* its port number. The client can connect to the server
running the service then,

The only means of communication between a server and a client are the two
streams: one for writing and one for reading. If you want to save a file somewhere
on the server's filing system you have to tell the server where you want to store
the file (i.e. you have to give the full path name of the new file on the server) and
you have to send the content you want to have in that file and preferably the size
of the content so the server knows what it can stop saving data and close the
file again. The way you do that (i.e. communicate what and how with the server)
is called the 'protocol'.

You either have to implement an already existing protocol or, when both the
server and the client(s) are made by you, you have to define your own protocol
for that, i.e. the file name, the content and its size have to be send to the server
somehow.

kind regards,

Jos
Mar 8 '08 #6
dmjpro
2,476 2GB
If a client wants to use a service it has to know the ip number of the host that
runs the service *and* its port number. The client can connect to the server
running the service then,

The only means of communication between a server and a client are the two
streams: one for writing and one for reading. If you want to save a file somewhere
on the server's filing system you have to tell the server where you want to store
the file (i.e. you have to give the full path name of the new file on the server) and
you have to send the content you want to have in that file and preferably the size
of the content so the server knows what it can stop saving data and close the
file again. The way you do that (i.e. communicate what and how with the server)
is called the 'protocol'.

You either have to implement an already existing protocol or, when both the
server and the client(s) are made by you, you have to define your own protocol
for that, i.e. the file name, the content and its size have to be send to the server
somehow.

kind regards,

Jos
I want use FTP protocol.
Could you help me to do that.
I think due to firewall I can't connect.
How could I do?

Debasis Jana
Mar 8 '08 #7
dmjpro
2,476 2GB
I want use FTP protocol.
Could you help me to do that.
I think due to firewall I can't connect.
How could I do?

Debasis Jana

Right now i made my local machine both ....Client and Server.
So ConnectException raised.
How could i configure FTP protocol in my Machine?

Debasis Jana
Mar 8 '08 #8
JosAH
11,448 Expert 8TB
Right now i made my local machine both ....Client and Server.
So ConnectException raised.
How could i configure FTP protocol in my Machine?

Debasis Jana
Google is your friend.

kind regards,

Jos
Mar 8 '08 #9
dmjpro
2,476 2GB
Google is your friend.

kind regards,

Jos
Thank you JOS for being with me for a long time with this Thread.
Actually I got a library org.apache.commons.net.********.
It's a very fantastic code.
Now do I need to define the protocol on Server to make it as FTP through Java Code?
Or something else(S/W) will help me to do that.

Please help!

Debasis Jana.
Mar 10 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Finch | last post by:
We are running SQL 7 on a Windows NT Server. If you copy a 25Mb file from this machine to a W2K server, the file copy takes over 5 minutes on a 100Mpbs switched network. Copying the same file to...
2
by: Paul | last post by:
Dear All, I want to use web form to upload my file and copy the file to another machine. I can upload the file, but when I copy the file(file.CopyTo(".....", true)) to another machine(map...
8
by: Ram Baruch | last post by:
Hi, I'm trying to use the File.Copy() function. It works well when the desenation file is local (Like: C:\dest\dest.exe). The problem is that when I'm trying to copy to a destenation that starts...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
2
by: .Net Believer | last post by:
I using the routine below to copy file to a network drive for a regular backup process. Before calling this routine I using another function to check the presence of the LAN connection and the...
1
by: John Wright | last post by:
During my program I load an exe file using reflection. My program loads the file using reflection, checks the assembly version and does an update if the network version is different from the local...
0
by: Paul Brady | last post by:
I volunteer at a youth ministry agency and help them with their student database. They have two computers, both running Windows XP. Both have Office 2002 installed without Access, except that...
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
9
by: Mantorok | last post by:
Hi all C# v2.0 I want to update a server which is in our DMZ, to access this server I always need to enter the admin user id and password. I want to copy some files overnight to this server...
1
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have problem with copying large number of files. Here is my code: foreach (FileInfo file in files) {...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.