Hello,
I have just finished writing the code for my FTP application but according to my code, everything should work fine. But when I run my application, the file is not transfer to the server. Can someone please check where I am going wrong. I am sending the code as attachment.

Please Note: I only want the Client to send a file to the Server for the time being.

Thanks in advance ...

In FTPServerReceiver you just have one input.read(), and it's not in a loop. Have you tried sending the buffer to System.out immediately after the read so you can see what's coming in?
Where exactly is it failing? - try to scatter some System.out.println statements around so you can see how far the client and server are getting, eg insidethe read /write loops

Hello,
I have changed the code, still not working, can you please check if its the right way to write to a file. Thanks a lot.

//read and write file
    public void run(){
 
        try{
            while(true){
                JOptionPane.showMessageDialog(null, "Server Receiver says: Incoming in progress ...");
                byte[] buffer = new byte[1024];
                int bytes = 0;
                input = new ObjectInputStream(thesocket.getInputStream());
                 //input.read(buffer,0,bytes);
                File f = new File(directoryName,"filetest");
                fout = new FileOutputStream(f);
                //fout.write(input.read(buffer,0,bytes));

                //new changes
                while(done){
                    if( (input.read(buffer,0,bytes)) == 0){
                        done = false;
                    }
                    else{
                        System.out.println(input.read(buffer,0,bytes));
                         fout.write(input.read(buffer,0,bytes));
                    }
                 }

            }

        }catch(Exception e){e.printStackTrace();}

        //JOptionPane.showMessageDialog(null, "Reception completed ...");

    }

Some quick comments:
"done" works backwards! Logically valid, but confusing. Can't see where it's declared or initialised.
EOF is signalled by -1, not 0. I don't know if EOF will ever get sent on a socket connection (unless the client closes the connection?).
The System.out reads the input stream, so it gets read twice in the loop! You should just print the buffer.
In writing the file you write the return value from the read. That's just the byte count. You need to write the buffer to the file.
You don't close the file.
Did you compile this; try to run it?

Sorry ... I declared done at the top as a boolean value and set to true.

boolean done = true

Yes .. I compiled it,no errors, the program run ... but its seems to work but the program does not write the file.

And I can't see the output of this piece of code:

System.out.println(input.read(buffer,0,bytes));

I changed the EOF to -1, still nothing. I tried to write the buffer ... still nothing. Please help me on this part , thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.