0

Possible Duplicate:
What’s causing my java.net.SocketException: Connection reset?

public void sendJobs(String hostname, int port, String username, String password, String folderName, Collection<File> files) throws Exception {
        FtpClient ftp = new FtpClient(hostname, port);
        ftp.login(username, password);
        ftp.binary();
        //ftp.cd("FTP_Hiring"); // this is for testing in Accel FTP. comment for other FTP
        if(folderName != "") {
              ftp.cd(folderName);
        }

        try {           
            for(File file : files) {
                FileInputStream fos = new FileInputStream(file);
                TelnetOutputStream tos = (TelnetOutputStream) ftp.put(file.getName());
                try {
                    //ftp.cd(file.getName().substring(0, file.getName().lastIndexOf(".")));
                    DataOutputStream dos = new DataOutputStream(tos);
                    byte[] buffer = new byte[1024 * 1024];
                    for (int length; (length = fos.read(buffer)) > 0;) {
                        dos.write(buffer, 0, length);
                    }

                    System.out.println("success");
                    tos.flush();
                    tos.close();
                    fos.close();    
                    ftp.cdUp();
                } catch(Exception e) {
                    hsLogger.error(e);
                    e.printStackTrace();
                } finally {
                    tos.close();
                    fos.close();    
                }
            }
        } catch(Exception e) {
            hsLogger.error(e);
            e.printStackTrace();
        }       
    }

Above given my code. I run it in a scheduler. But in the line

TelnetOutputStream tos = (TelnetOutputStream) ftp.put(file.getName()); I get the following exception

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    at sun.net.TransferProtocolClient.readServerResponse(TransferProtocolClient.java:49)
    at sun.net.ftp.FtpClient.readReply(FtpClient.java:217)
    at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:193)
    at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:383)
    at sun.net.ftp.FtpClient.put(FtpClient.java:594)
    at com.hiringsteps.ats.util.net.service.impl.JobXMLManagerService.sendJobs(JobXMLManagerService.java:1883)
    at com.hiringsteps.ats.util.net.service.impl.JobXMLManagerService.postJobs(JobXMLManagerService.java:273)
    at com.hiringsteps.ats.job.facade.impl.JobFacade$2.jobPosting(JobFacade.java:2031)
    at com.hiringsteps.ats.job.facade.impl.JobFacade$2.run(JobFacade.java:1935)
    at com.hiringsteps.ats.util.scheduler.service.impl.Scheduler$SchedulerTimerTask.run(Scheduler.java:20)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Community
  • 1
  • 1
skmaran.nr.iras
  • 8,152
  • 28
  • 81
  • 116
  • 1
    there are questions asked before. http://stackoverflow.com/questions/585599/whats-causing-my-java-net-socketexception-connection-reset take a look at this link – snow8261 Jan 29 '13 at 05:29

2 Answers2

1

This Exception might mean that there is Error happening at the underlying layers of network i.e TCP layers.

TCP packets are not getting ACK signals back from the server.

This needs further analysis of the network packets using Networks packet analysis tools like Wire shark

OR

Try to implement a re-try mechanism (but still i recommend to find the root cause from the network layer)

One more observation, As the error reads Connection Reset and not connecton reset by peer .Suspect the error cause it at the client side.

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
1

This exception has several causes, but the most common is that you wrote to a connection which had already been closed by the peer, which causes the peer to send a TCP RST segment (a reset). In other words, an application protocol error.

user207421
  • 305,947
  • 44
  • 307
  • 483