473,569 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File copy over Network.

dmjpro
2,476 Top Contributor
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 9678
JosAH
11,448 Recognized Expert MVP
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 Top Contributor
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+particu lar 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 Top Contributor
If I want to copy to that destined machine+particu lar 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 Top Contributor
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 Recognized Expert MVP
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 Top Contributor
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 Top Contributor
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 ConnectExceptio n raised.
How could i configure FTP protocol in my Machine?

Debasis Jana
Mar 8 '08 #8
JosAH
11,448 Recognized Expert MVP
Right now i made my local machine both ....Client and Server.
So ConnectExceptio n 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 Top Contributor
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.comm ons.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
1954
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 another NT server takes only seconds, and copying the same file to the W2K server from the 2nd NT server, (which is not running SQL) takes only...
2
5950
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 network driver), it failed(error message : login failed......). So.... how should I do if I want the upload file can copy to another machine. Thanks !!
8
17025
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 with '\\' it doesnt work and exception is thrown (for example: \\MyComputer\DestDirectory). Even if the first and the second directories are actually...
8
9712
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 problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC...
2
2663
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 server where the network drive exists. Although of this check I am sometimes getting an exception (in 5% of times)saying "Could not find the...
1
2236
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 version. I have a problem, however, when I do the first check using reflection to get the network version, then it locks the file and I can't...
0
2592
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 Computer A had A97. They wanted both computers to be able to use the database, stored on Computer A. I can't get them to do that, and it seems to be...
3
2683
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, lsRecordType, lsXNbr, lsFiscYr, "Beg", CStr(H.BegBalAccDepn), CStr(H.BegBalCost), CStr(H.BegBalCostReval), CStr(H.BegBalDepCost), CStr(H.BegBalDepnReval)) ...
9
12005
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 using a C# app, is this possible? Can I provide the credentials to enable me to access the server?
1
4259
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) { File.Copy(file.FullName,destPath+ "\\" + file.Name, true); } This code copies only 5 or 10 files but in "files" collection there is 60 files.
0
8144
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7692
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7992
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3677
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3666
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1235
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
969
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.