套接字 – 通过对等方重置连接:ftp期间的套接字写入错误

在尝试向服务器ftp(使用隐式ssl)文件时,我始终得到“对等连接重置:套接字写入错误”或异常“软件连接中断”错误.该文件已上载到服务器,但完全为空.但是,在设置本地测试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$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)

最佳答案 我找到了答案.添加以下两行:

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