Reset by peer connection: error writing socket during ftp

When trying to ftp (with an implicit ssl) file on the server, I consistently get the message "Connection Reset By Peer: Socket Write Error" or abnormally "Connection with software interrupt." The file is uploaded to the server, but is completely empty. However, after setting up a local test ftp server, I upload files to that server with no problem. Could these errors be caused by some kind of firewall? If not, there is another problem. If so, is there anything you can change in the code to fix this?

Using Apache Commons:

String SFTPHOST = compParam.getSftpHostNme();
int SFTPPORT = 990;
String SFTPUSER = compParam.getSftpLogin();
String SFTPPASS = compParam.getSftpPassword();
            FTPSClient ftpClient = new FTPSClient(true);
    try {

        ftpClient.connect(SFTPHOST, SFTPPORT);
        if(!ftpClient.login(SFTPUSER, SFTPPASS)){
            SwingUtils.showMessage(this, "Error: Trouble Connecting \n" + "User Name and Password or Host is incorrect \n"
                    + "or someone else is using these credentials");
            return;
        }
        ftpClient.enterLocalPassiveMode();
        ftpClient.setFileType(FTP.ASCII_FILE_TYPE);

        File f = new File(TLCTripRecordExportDlg.filePath + TLCTripRecordExportDlg.fileName);

        String remoteFile = TLCTripRecordExportDlg.fileName;
  FileInputStream inputStream = new FileInputStream(f);
  ProgressMonitorInputStream pmiStream = new ProgressMonitorInputStream(this,"Uploading the File",inputStream);
//      OutputStream os = ftpClient.storeFileStream(remoteFile);
//      byte[] buffer = new byte[1024];
//      int len;
//      while ((len = pmiStream.read(buffer)) != -1)
//      {
//          os.write(buffer, 0, len);
//          os.flush();
//      }
//      pmiStream.close();
//      os.close();


  if(ftpClient.storeFile(remoteFile, pmiStream)){
    inputStream.close();
    pmiStream.close();
  }else{

    SwingUtils.showMessage(this, "File Not Uploaded: " + ftpClient.getReplyString());
    return;
  }

      

The error is being loaded into the repository file. Here's the stack trace:

 java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
    at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
    at com.limosys.gui.job.TLCTripUploadDlg.upload_actionPerformed(TLCTripUploadDlg.java:261)
    at com.limosys.gui.job.TLCTripUploadDlg$3.actionPerformed(TLCTripUploadDlg.java:193)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6290)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6055)
    at java.awt.Container.processEvent(Container.java:2039)
    at java.awt.Component.dispatchEventImpl(Component.java:4653)
    at java.awt.Container.dispatchEventImpl(Container.java:2097)
    at java.awt.Component.dispatchEvent(Component.java:4481)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
    at java.awt.Container.dispatchEventImpl(Container.java:2083)
    at java.awt.Window.dispatchEventImpl(Window.java:2482)
    at java.awt.Component.dispatchEvent(Component.java:4481)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:607)
    at java.awt.EventQueue$1.run(EventQueue.java:605)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:621)
    at java.awt.EventQueue$2.run(EventQueue.java:619)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
    at java.awt.Dialog$1.run(Dialog.java:1044)
    at java.awt.Dialog$3.run(Dialog.java:1096)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Dialog.show(Dialog.java:1094)
    at java.awt.Component.show(Component.java:1584)
    at java.awt.Component.setVisible(Component.java:1536)
    at java.awt.Window.setVisible(Window.java:841)
    at java.awt.Dialog.setVisible(Dialog.java:984)
    at com.limosys.gui.dialogs.gen.GenDialog.setVisible(GenDialog.java:250)
    at com.limosys.gui.job.TLCTripUploadDlg.showIt(TLCTripUploadDlg.java:325)
    at com.limosys.gui.job.TLCTripExport$ExportTLCTripTask.invoke(TLCTripExport.java:363)
    at com.limosys.dblib.utils.JLimoWorker$1.run(JLimoWorker.java:169)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:607)
    at java.awt.EventQueue$1.run(EventQueue.java:605)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

      

+3


source to share


1 answer


I found the answer. Add these two lines:



        ftpClient.execPROT("P");
        ftpClient.execPBSZ(0);

      

+1


source







All Articles