对等方重置连接:ftp 期间出现套接字写入错误

Connection reset by peer: socket write error during ftp

在尝试 ftp(使用隐式 ssl)将文件发送到服务器时,我始终收到 'Connection Reset By Peer: Socket Write Error' 或异常的 'Connection Aborted By Software' 错误。该文件已上传到服务器,但完全是空的。但是,在设置本地测试 ftp 服务器后,我可以毫无问题地将文件上传到该服务器。这些错误可能是由某种类型的防火墙引起的吗?如果不是,是否还有其他问题。如果是,是否可以更改代码中的任何内容来修复它?

使用 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;
  }

存储文件中出现错误。这是堆栈跟踪:

 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.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[=12=]0(EventQueue.java:84)
    at java.awt.EventQueue.run(EventQueue.java:607)
    at java.awt.EventQueue.run(EventQueue.java:605)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue.run(EventQueue.java:621)
    at java.awt.EventQueue.run(EventQueue.java:619)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext.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.run(Dialog.java:1044)
    at java.awt.Dialog.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.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[=12=]0(EventQueue.java:84)
    at java.awt.EventQueue.run(EventQueue.java:607)
    at java.awt.EventQueue.run(EventQueue.java:605)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext.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)

我找到了答案。添加这两行:

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