Folder transfer using sockets

Is there anyway to transfer the whole folder including the subfolders
using sockets.
i can transfer the all the files one by one
but it needs lot of coding like making subfolders in the destination and etc.
i need to send a folder using a single outputstream
Thanks
Ananth

Ananthakumaran wrote:
tar and untar will take some time Really? Have you measured that?
I'll bet if you look, the time it takes is completely dominated by the need to read the files on one side and write the files on the other. Since any copy program has to do the same thing, this should be no slower than any other method.
and mostly my app is used to transfer large size file
i need something which can send folder like a single file without any >>> overhead >>>Everything you do has overhead. You want to send files and folders over the network. Using tar to serialize that structure has very little overhead. I doubt the overhead will be visible given the need to actually read and write the files.
Darren

Similar Messages

  • Folder transfer over sockets!

    How can I transfer folders over the socket?
    Also in File transmission is it required to use BufferedInputStream or Output/InputStream alone can do the work?

    rameshraj wrote:
    How can I transfer folders over the socket?
    Also in File transmission is it required to use BufferedInputStream or Output/InputStream alone can do the work?Conceptually yes.
    Technically no.
    Sockets send data.
    A 'folder' represents a resource on the computer. Thus you can no more send that than you can send your physical hard drive.
    So conceptually if you wanted to simulate a copy.
    1. Design a data structure that allows you to encapsulate the folder structure (folder names, file names, file dates, file contents perhaps file permisions.)
    2. Create an API that allows you to create that data structure (fill it in) when pointed to a folder.
    3. Create an API that sends that data structure via a socket.
    4. Create an API that receives that data structure via a socket.
    5. Create an API that takes a data structure and create folders, files, etc from it.
    Note that 2-5 are code but 1 is not. And you do not start untile 1 is complete.
    Or as an alternative to the above learn how FTP works and use that instead.

  • Problem on image transfer using Socket

    There are a server and a client,
    server executes the code:
    ImageIO.write( bufferedImage, "jpg", outputStream );
    System.out.println("writed");client executes the code:
    BufferedImage bufferedImage = ImageIO.read( inputStream );
    System.out.println("read");The problem is that the string "writed" is displayed at the console of the server, but the client is blocking at the method ImageIO.read().
    However, when I add one more line of code to the server:
    ImageIO.write( bufferedImage, "jpg", outputStream );
    outputStream.close();
    System.out.println("writed");The problem is solved but I don't want to close the outputStream.
    I would like to ask is there any idea to solve this problem without close the outputStream?
    Thank you very much.

    I would like to ask is there any idea to solve this
    problem without close the outputStream?Send a message not data.
    You now just shove data down the pipe. The other end has no way to know when the data has arrived.
    Wrapping data in a message provides a way to determine that all of the data has arrived. This also means that you need a communication API. That is an api that
    1. Takes data as input
    2. Packages it in a message.
    3. Sends the message.
    4. Recieves a message
    5. Unpackages the data
    6. Returns the data as output.

  • Oracle BAM to monitor transfer of files using sockets

    Hi,
    We have two programs transferring files using sockets. We wanted BAM to monitor the transfer.
    Would you please suggest if this is achievable in BAM , and if so , any pointers to how we may go about implementing it .
    Cheers,
    Anant.

    You could generate success/failure/progress from your utility to JMS or call BAM webservices to populate BAM Data Objects. Reports could be built on top of that.

  • File transfer using non-blocking sockets - data mysteriously  vanish

    Hello,
    I need to pass some big amount of data using sockets. I my appliaction I have noticed that sometimes I didn't get all bytes. To check it out I wrote simple client + server to figure out what is happening. So:
    - I have a sender and receiver application
    - I'm trying to transfer 5MB text file.
    - On receiver side, output file is never larget than 3MB
    - If I put some timeout on sender side (1ms timeout between write operations) everything works fine.
    Could someone tell me what I do wrong? Why data disappears and when? The same file transfered using old sockets goes always fine...
    Thanks in advance!
    Here is complete source for receiver and sender:
    RECEIVER:
    import java.io.FileOutputStream;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    public class ReceiverA {
          * @param args
         public static void main(String[] args) {
              String outputFile = "c:\\outputA.txt", host = "127.0.0.1";          
              int port = 8001, bufferSize = 10240;
              try {
                   ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
                   Selector selector = Selector.open();
                   ServerSocketChannel server = ServerSocketChannel.open();
                   server.configureBlocking(false);
                   server.socket().bind(new InetSocketAddress(host, port));
                   server.register(selector, SelectionKey.OP_ACCEPT);
                   System.out.println("Server started");
                   while(true)
                        selector.select();
                        Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();
                        while (iterator.hasNext()) {
                             SelectionKey key = (SelectionKey) iterator.next();
                             iterator.remove();
                             if (key.isAcceptable()) {                              
                                  SocketChannel client = server.accept();
                                  client.configureBlocking(false);
                                  client.register(selector, SelectionKey.OP_READ);                              
                                  continue;
                             SocketChannel channel = (SocketChannel) key.channel();
                             int counter = 1;
                             if ( key.isReadable() ) {
                                  FileOutputStream os = new FileOutputStream(outputFile);
                                  int res;
                                  do
                                       buffer.clear();
                                       res = channel.read(buffer);
                                       counter += res;
                                       System.out.println(res);
                                       buffer.flip();
                                       os.write(buffer.array(), 0, buffer.limit());
                                  while( res >= 0 );          
                                  channel.close();
                                  os.close();          
                                  System.out.println("Receiver: " + counter);
                                  return;
              } catch (Exception e) {
                   e.printStackTrace();
    }SENDER:
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    public class SenderA {
         public static void main(String[] args) {
              String inputFile = "c:\\inputA.txt" , host = "127.0.0.1";          
              int port = 8001, bufferSize = 10240;
              try {
                   ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
                   byte[] byteArr = new byte[buffer.capacity()];
                   Selector selector = Selector.open();
                   SocketChannel connectionClient = SocketChannel.open();     
                   connectionClient.configureBlocking(false);
                   connectionClient.connect(new InetSocketAddress(host, port));
                   connectionClient.register(selector, SelectionKey.OP_CONNECT);
                   while(true) {
                        selector.select();
                        Iterator<SelectionKey> iterator = selector.selectedKeys()
                                  .iterator();
                        while (iterator.hasNext()) {
                             SelectionKey key = (SelectionKey) iterator.next();
                             iterator.remove();
                             SocketChannel client = (SocketChannel) key.channel();
                             if (key.isConnectable()) {
                                  if (client.isConnectionPending()) {
                                       System.out.println("Trying to finish connection");
                                       try {
                                            client.finishConnect();
                                       } catch (IOException e) {
                                            e.printStackTrace();
                                  client.register(selector, SelectionKey.OP_WRITE);
                                  continue;
                             if(key.isWritable()) {
                                  FileInputStream is = new FileInputStream(inputFile);
                                  int res;
                                  int counter = 0;
                                  do
                                       buffer.clear();
                                       res = is.read(byteArr, 0, byteArr.length);                                   
                                       System.out.println(res);
                                       if ( res == -1 ) break;
                                       counter += res;
                                       buffer.put(byteArr, 0, Math.min(res, buffer.limit()));
                                       buffer.flip();
                                       client.write(buffer);
                                        * When I remove comment file transfer goes OK!
                                       //Thread.sleep(1);
                                  while( res != -1 );          
                                  client.close();
                                  is.close();          
                                  System.out.println("Receiver: " + counter);
                                  return;
              catch(Exception e) {
                   e.printStackTrace();
    }

    There are at least two problems here.
    A. In the receiver you should test for -1 from the read() immediately, rather than continue with the loop and try to write -1 bytes to the file.
    B. In the sender you are ignoring the return value of client.write(), which can be anything from 0 to the buffer length. If you get 0 you should wait for another OP_WRITE to trigger; if you get a 'short write' you need to retry it until you've got nothing left to write from the current buffer, before you read any more data. This is where the data is vanishing.

  • How to Transfer files using socket remote method invocation?

    hello guys,
    i am working on java sockets...and i need to send and receive files though Java RMI. how will i go with it....
    Please do help me in this regard
    Edited by: sandeep_genevsoftech on Apr 4, 2008 4:32 AM

    I am also developing a similar application of file transfer but using sockets in place of RMI.The file gets transfered if i run client and server on same m/c(as localhost),but shows "access denied" if run on different m/c.I suppose some security policies need to be set.Can anybody help?

  • Two applications wants to read on the same port using Socket

    I have an application running on one machine using TCP/IP socket. The data transfer with the other application on other machine is in ASCII.
    Now I want a new application that can have a copy of data received and sent on the given port, where the previous application is running.
    Is it possible in Java using socket and TCP/IP to have two application reading data from the same port and both can read all the data.

    Even when you don't state the type of app which need to read the data stream (is it a server or a client app???), it's impossible to share a single TCP/IP socket among multiple apps.
    Perhaps the best thing to do is to develop something like a proxy server who listens on the nominated port and provides to contact (if your apps are server ones) or to be contacted (if your apps are client ones) by the desired apps.
    This way, the only job for the proxy is to duplicate the contents of the data stream and make them available to all the apps engaged.
    Hope this helps.

  • Sending file using sockets (difficult)

    Hi, i have the following section of code
    (of which i am not claiming ownership) which
    implements a DCC Send command from irc.
    It accomplishes this using sockets, and while
    i understand how the code accomplishes what it
    does, i need help with a possible modification.
    Basically what i am looking to do is keep track
    of the progress of the send - so that the
    user can at any time see how much of the file
    has been sent and how much is remaining.
    If anyone has done such a thing in the past or
    has a good idea as to how this should be implemented,
    i would be greatful for their help.
    Here is the code:
    new Thread() {
                public void run() {
                    try {
                        ServerSocket ss = new ServerSocket(0);
                        ss.setSoTimeout(timeout);
                        int port = ss.getLocalPort();
                        //byte[] ip = ss.getInetAddress().getAddress();
                        byte[] ip = InetAddress.getLocalHost().getAddress();
                        long ipNum = 0;
                        long multiplier = 1;
                        for (int i = 3; i >= 0; i--) {
                            int byteVal = (ip[i] + 256) % 256;
                            ipNum += byteVal*multiplier;
                            multiplier *= 256;
                        // Rename the filename so it has no whitespace in it when we send it.
                        // .... I really should do this a bit more nicely at some point ....
                        String safeFilename = file.getName().replace(' ', '_');
                        safeFilename = safeFilename.replace('\t', '_');
                        // Send the message to the user, telling them where to connect to in order to get the file.
                        sendCTCPCommand(nick, "DCC SEND " + safeFilename + " " + ipNum + " " + port + " " + file.length());
                        // The client may now connect to us and download the file.
                        Socket socket = ss.accept();
                        socket.setSoTimeout(30000);
                        // Might as well close the server socket now; it's finished with.
                        ss.close();
                        BufferedOutputStream output = new BufferedOutputStream(socket.getOutputStream());
                        BufferedInputStream input = new BufferedInputStream(socket.getInputStream());
                        BufferedInputStream finput = new BufferedInputStream(new FileInputStream(file));
                        byte[] outBuffer = new byte[bufferSize];
                        byte[] inBuffer = new byte[4];
                        int bytesRead = 0;
                        while ((bytesRead = finput.read(outBuffer, 0, outBuffer.length)) != -1) {
                            output.write(outBuffer, 0, bytesRead);
                            output.flush();
                            input.read(inBuffer, 0, inBuffer.length);
                        output.close();
                        input.close();
                        log("+++ DCC SEND Completed to " + nick + " (" + file.getPath() + ")");
                    }

    You already have the necessary code to find the number of bytes sent at any point during the transmission. You can find out the size of the file by instantiating a RandomAccessFile before you send it, and querying for the file length.
    I suggest you make the file size and bytes sent volatile and conveniently accessible to another thread (best implemented here as an inner class?). Your new thread will need to monitor the file transfer at intervals to update the progress indicator. You can generate estimates of time remaining by measuring the average transmission rate, and extrapolating using the total file size. Classically this is done using an average, but you might be better just maintaining a list of fairly recent samples, allowing for the speed swings inherent in internet connections.
    How you update the progress indicator from your monitor thread is up to you. I suggest exposing methods in the UI for setting the progress and time remaining, and simply update them from the monitor.
    Does this help any?

  • File to file transfer using UDF

    Hi
      i am doing one scenario,file tofile transfer using UDF.
    I will write one UDF which will read the whole content from text file and write to the target path.Ok.so i am mentioning both sender and reciver URL in UDF.is this the correct way.
    then if am writing URL in UDF then is it again need to create  communication channel for both.
    and how i will do mapping  using UDF..plz let me know  weather my concept is correct or not

    Hi,
    You can do this with out UDF and through File--File Simple Scenario
    What is your Typical requirement to use the UDF here.
    If there is no Specific UDF Requirement means , we can follow Normal Scenario to pick the file from One place and to place it at another folder
    File to File scenario:
    Introduction to simple(File-XI-File)scenario and complete walk through for starters(Part1) - File to File Part 1
    Introduction to simple (File-XI-File)scenario and complete walk through for starters(Part2) - File to File Part 2
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/flatFILETOFLATFILE&
    REgards
    Seshagiri

  • How to open multi-windows to operate a remote compute using socket

    hi, please help me.
    I want to develop a program, it can open multi-windows to operate the remote comput at one time just like NetTerm. It use socket to setup connection with remote computer.
    Now I am using a Thread class to setup socket connection with computer, and use Thread's static varible to control all kinds of action of socket.But it can work only when openning one window,because all the thread instances share the same static variable.
    How to do it? Not using Thread? Then the frame will be frozen.
    All adivse are welcomed.Thank you.

    Maybe I don't say it clearly.The program need to show the output of the socket in the JTextArea and transfer the user input to the input of the socket to control the remote computer.

  • Fast file transfer via sockets

    Hi,
    I have made little program that sends files via lan to my other computer using sockets (ServerSocket and Socket). When I code my program to use only FileInputStream and FileOutputStream throught the sockets I get only speed about 100Kbs even when I run them in localhost.
    I would really like to have examples of faster way to send and receive files throught sockets? Any samples using buffers or compressing data would be very nice. Thank you very much in advance!
    Sincerely,
    Lauri Lehtinen

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    * FileServer.java
    * Created on January 18, 2005, 2:21 PM
    * @author  Ian Schneider
    public class FileServer {
        static class Server {
            Socket client;
            public Server() throws Exception {
                ServerSocket s = new ServerSocket(12345);
                while (true) {
                    client = s.accept();
                    File dest = new File(System.getProperty("java.io.tmpdir"),"transfer.tmp");
                    InputStream data = client.getInputStream();
                    OutputStream out = new FileOutputStream(dest);
                    byte[] bytes = new byte[1024];
                    int l = 0;
                    int cnt = 0;
                    long time = System.currentTimeMillis();
                    while ( (l = data.read(bytes)) >= 0) {
                        cnt += l;
                        out.write(bytes,0, l);
                    int kb = cnt / 1024;
                    int sec = (int) (System.currentTimeMillis() - time) / 1000;
                    System.out.println("transfered " + kb/sec);
                    out.flush();
                    out.close();
                    client.close();
        static void writeToServer(String fileName) throws Exception {
            Socket s = new Socket("localhost",12345);
            OutputStream out = s.getOutputStream();
            FileInputStream in = new FileInputStream(fileName);
            byte[] bytes = new byte[1024];
            int l = 0;
            while ( (l = in.read(bytes)) >= 0) {
                out.write(bytes,0,l);
            out.flush();
            out.close();
            in.close();
        public static final void main(String[] args) throws Exception {
            if (args[0].equals("server")) {
                new Server();
            } else {
                writeToServer(args[1]);
    }You may see improvements by buffering these. I didn't bother testing.

  • Reading / Writing files using Sockets

    Hi there guys,
    I am fairly new to this forum. I have been having a problem for the past three days. I am implementing a client/server implementation using Sockets which is a submodule of a project I am working on. What I want is that a files content are read and transferred over the network to the server that writes it down to a different file .
    What the code presently does is :
    <<<<Client Code >>>>
    It reads a file input.txt and sends the content over the network to the server.
    <<<< Server Code >>>
    It reads the incoming data from the client and writes the data out to a file called output.txt
    What I want now is that the server should read the file output.txt and send the contents to the client which reads it and then writes it down as a new file called serverouput.txt . After that I want to compare and see of the size of input.txt and serveroutput.txt . If both are same that means that data has been written reliably to the server.
    I have been trying to implement it for a long time and nothing seems to work out. I am posting the code for both client and server below. Any help in finalising things would be really appreciated.
    CLIENT CODE
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.io.*;
    import java.net.*;
    class sc {
    static final int PORT = 4444;          //Change this to the relevant port
    static final String HOST = "127.0.0.1";
         //Change this to the relevant HOST,
    //(where Server.java is running)
    public static void main(String args[]) {
    try {
    System.out.print("Sending data...\n");
    Socket skt = new Socket(HOST, PORT);
                   // Set the socket option just in case server stalls
    skt.setSoTimeout ( 2000 );
                   skt.setSoKeepAlive(true);
    //Create a file input stream and a buffered input stream.
    FileInputStream fis = new FileInputStream("input.txt");
    BufferedInputStream in = new BufferedInputStream(fis);
    BufferedOutputStream out = new BufferedOutputStream( skt.getOutputStream() );
    //Read, and write the file to the socket
    int i;
    while ((i = in.read()) != -1) {
    out.write(i);
    //System.out.println(i);
                   // Enable SO_KEEPALIVE
    out.flush();
    out.close();
    in.close();
    skt.close();
    catch( Exception e ) {
    System.out.print("Error! It didn't work! " + e + "\n");
              catch( IOException e ) {
    System.out.print("Error! It didn't work! " + e + "\n");
    SERVER CODE
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.io.*;
    import java.net.*;
    class ClientWorker implements Runnable {
    private Socket client;
    ClientWorker(Socket client) {
    this.client = client;
    public void run(){
    try      {
    FileOutputStream fos = new FileOutputStream("output.txt");
    BufferedOutputStream out = new BufferedOutputStream(fos);
    BufferedInputStream in = new BufferedInputStream( client.getInputStream() );
    //Read, and write the file to the socket
    int i;
    while ((i = in.read()) != -1) {
    out.write(i);
    //System.out.println(i);
    System.out.println("Receiving data...");
    out.flush();
    in.close();
    out.close();
    client.close();
    // srvr.close();
    System.out.println("Transfer complete.");
    catch(Exception e) {
    System.out.print("Error! It didn't work! " + e + "\n");
    class ss1 {
    ServerSocket server = null;
    ss1(){ //Begin Constructor
    } //End Constructor
    public void listenSocket(){
    try{
    server = new ServerSocket(4444);
    } catch (IOException e) {
    System.out.println("Could not listen on port 4444");
    System.exit(-1);
    while(true){
    ClientWorker w;
    try{
    w = new ClientWorker(server.accept());
    Thread t = new Thread(w);
    t.start();
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    protected void finalize(){
    //Objects created in run method are finalized when
    //program terminates and thread exits
    try{
    server.close();
    } catch (IOException e) {
    System.out.println("Could not close socket");
    System.exit(-1);
    public static void main(String[] args){
    ss1 frame = new ss1();
         frame.listenSocket();
    }

    ............................................. After that I want to
    compare and see of the size of input.txt and
    serveroutput.txt . If both are same that means that
    data has been written reliably to the server.You don't need to do this. TCP/IP ensures the reliable transmition of data. By using a socket you are automaticaly sure that the data is reliably transmitted (Unless there is some sort of exception).
    To get the size of the files you can use a File object. Look it up in java.io package in API documentation.
    java-code-snippet (without error checking)
    File clientFile = new File("input.txt");
    clientFile.length();

  • Data Transfer with Socket

    Hi,
    we want to transfer some arrays using socket.
    On the server side we send two array (arrays of byte of ~50 Kbytes) with:
    PrintStream out = new PrintStream(client.getOutputStream(), true)
    out.write(Array of byte).
    On the client side we do not receive two stream of data of 50Kbyte, but we receive two or more stream of different size using:
    BufferedInputStream in = new BufferedInputStream(s.getInputStream()) in.read(Msg).
    Server side:
    Send Array1;
    Send Array2;
    Client Side:
    get Stream1;
    get Stream2;
    get Stream3;
    Stream1 = part of Array1
    Stream2 = remaining of Array1 and part of Array 2
    Stream3 = remaining of Array2
    Is it possible to receive each array in one stream each and not fragmented in different stream ??
    What we wanna is:
    Server side:
    Send Array1;
    Send Array2;
    Client side:
    get Stream1 (= Array1)
    get Stream2 (= Array2)
    Best Regs

    I didn't quite understand your post, given your mix of Java code and pseudocode.
    However, I shall attempt to give you some guidance:
    When you say you are using multiple streams, I am assuming that you are only using 1 stream, but reading in from it multiple times.
    With a network connection, delivery over the stream of all the content at one time cannot be guranteed. In practical terms this means that you cannot do the following:
    Server:
    send 50kb of data
    Client:
    receive 50kb of data.
    Close connection.
    What you have to do instead is:
    Server:
    send 50kb of data
    Client:
    read from stream until 50kb of data have been read.
    Close connection.
    For the above to work, you must know that you are expecting 50kb of data. If you don't know how big the data stream is going to be, there are two solutions:
    Solution 1: include length of data in send:
    Server:
    send 2 bytes representing the length of the data (in this case 12bk)
    send 12kb of data
    Client:
    read length of stream (2 bytes. Should give you 12kb).
    read 12kb of data.
    Close connection.
    Solution 2: include batch separators:
    This solution is when you want to send a number of batches down the same line (kindda what you want).
    Server:
    send 50kb of data
    send separator (e.g. '|''|')
    send 34kb of data
    Client:
    read stream until stream is closed, or separator encountered.
    if separator encountered, create new data batch, continue as above.
    The problem with solution 2, is that you now have to devise an appropriate way for escaping the separator. If the separator occurs naturally in the data you are sending, you should escape it on sending, and unescape it on reading in at the other end.
    However, after all of the explanation above, my advise to you is: use the ObjectOutputStream and the ObjectInputStream classes. With these, you should be able to send and receive the array with no problems. Follow the advice in the JavaDocs and possibly the Java Tutorial for more info on using the ObjectStreams.
    Regards,
    Manuel Amago.

  • Use Socket to send a File

    I'm looking for the best method to send a Text file to a Mainframe box using sockets, I know that I can do this whit FTP, but I'm trying to get the best way to do it, if anybody can give me an idea I'll appreciate that,
    Thank & Regards

    You'll need to elaborate on your requirements to get the best solution... Otherwise, you'll be hard pressed to find something better than FTP. It's a standardised protocol for file transfer. What more could you want?

  • Filestreaming using sockets

    I have written a server and a client for streaming a file. Client to server. I have tried a lot of code to get a file streamed from client to server, but either nothing happens or it's only 16 kb (byte array) arriving and the last result - the server keeps writing (never stops) to the file output making the file grow rapidly and far beyond the size of the transmitted file. I know that file streaming should be the same whether it's local file handling or using sockets. I have the local file streaming working fine, but converting it to sockets doesn't work. So this server/client is a new approach using byte array. Still doesn't work. Can anyone help? Alternatively give me a link to a working code for this job. Thank you. :)
    Client
    import java.io.*;
    import java.net.Socket;
    public class my_client {
         public static void main(String[] args) throws IOException{
                   String server = args[0];
                   int port = Integer.parseInt(args[1]);
                   String filename = args[2];
                   Socket socket = new Socket(server, port);
                   System.out.println("Connected at " + socket.getLocalSocketAddress());
                   OutputStream fout = socket.getOutputStream();
                   FileInputStream bis = new FileInputStream(filename);
                   byte[] data = new byte[1024];                         
                   int totalTx = bis.read(data);          
                   while(totalTx != -1){
                        fout.write(data, 0, totalTx);
                        fout.flush();
                   socket.shutdownOutput();
                   socket.close();
    }Server
    import java.net.*;
    import java.io.*;
    public class my_server {
         public static void main(String[] arg) throws IOException{
              if(arg.length != 1) throw new IllegalArgumentException("Parameter: <port>");
         int servPort = Integer.parseInt(arg[0]);
         ServerSocket servSock = new ServerSocket(servPort);
         while(true){
              Socket clntSock = servSock.accept();
              SocketAddress clntAddress = clntSock.getRemoteSocketAddress();
              System.out.println("Handling client at " + clntAddress);
              InputStream in = clntSock.getInputStream();
              FileOutputStream fout = new FileOutputStream("incomming.txt");
              byte[] data = new byte[1024];
              int totalRx = in.read(data);
              while(totalRx != -1){
                   fout.write(data, 0, totalRx);
              fout.close();
              in.close();
              clntSock.close();
    }

    1. Your read are outside your while loops.
    2. There is a whole protocol standard for file transfer called FTP = File Transfer Protocol.
    3. There is also a networking forum where socket questions are best asked.
    4. Your sever is single threaded so you can only handle one read at a time.

Maybe you are looking for