将多个文件从ftps服务器传输到Liferay Portal

将多个文件从ftps服务器传输到Liferay Portal,ftp,liferay,sftp,ftp-client,Ftp,Liferay,Sftp,Ftp Client,我们有一个客户端FTP服务器,他们在/dev目录中上传多个pdf文件。pdf文件的模式为[Organization\u NAME]\u CR.pdf。我们正在检索这些文件,并根据[组织机构名称]将其上载到我们的Liferay文档库 我们在使用单个ftp连接检索多个文件时遇到问题。第一次检索当前目录/dev的文件列表并在Liferay文档库中上载时。但当它试图检索第二个文件时,它将文件长度返回为零,并将引发错误作为异常发送警报:java.net.SocketException:Connection

我们有一个客户端FTP服务器,他们在/dev目录中上传多个pdf文件。pdf文件的模式为[Organization\u NAME]\u CR.pdf。我们正在检索这些文件,并根据[组织机构名称]将其上载到我们的Liferay文档库

我们在使用单个ftp连接检索多个文件时遇到问题。第一次检索当前目录/dev的文件列表并在Liferay文档库中上载时。但当它试图检索第二个文件时,它将文件长度返回为零,并将引发错误作为异常发送警报:java.net.SocketException:Connection reset by peer:socket write error: 连接关闭,无指示

请参考下面的代码

public static void importReports() {
    InputStream is = null;
     System.setProperty("javax.net.debug", "ssl");
     FTPSClient ftpClient = new FTPSClient();
    try 
    {

            // Store file on host
             ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
           // Connect to host
            ftpClient.connect(hostname);
            int reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftpClient.disconnect();
                System.exit(1);
            }
            if (!ftpClient.login(loginname), PortletProps.get(password))) {
                ftpClient.logout();
                System.exit(1);
            }
            // Set protection buffer size
            ftpClient.execPBSZ(0);
            // Set data channel protection to private
            ftpClient.execPROT("P");
        try{
              List<Organization> orgList = OrganizationLocalServiceUtil.getOrganizations(-1, -1);
              for (Organization organization : orgList) {
                                String folderPath ="/dev";
                                String ftpfileName = organization.getName();
                                String ftpFilePath = folderPath+StringPool.FORWARD_SLASH+ftpfileName;
                                ftpClient.changeWorkingDirectory(folderPath); 
                                // Enter local passive mode
                                ftpClient.enterLocalPassiveMode();
                                ftpClient.setRemoteVerificationEnabled(false);
                                FTPFile[] files = ftpClient.listFiles(folderPath);
                                for(FTPFile file : files)
                                {
                                    if(file.isFile() && file.getSize() > 0 && file.getName().equalsIgnoreCase(ftpfileName))
                                    {

                                        try{
                                            is = ftpClient.retrieveFileStream(ftpFilePath);
                                            if (Validator.isNotNull(is)) {

                                             ftpClient.completePendingCommand();
                                        }catch(SocketException se)
                                        {
                                            LOGGER.info("SocketException  :"+se.getMessage());  
                                        }
                                    }
                                }

                            }
                // Logout
                ftpClient.logout();
                // Disconnect
                ftpClient.disconnect();
        }
        catch(PortalException e)
        {
            LOGGER.info(e.getMessage());
        } catch (SystemException e) {
            LOGGER.info(e.getMessage());
        }
    } catch (IOException ioe) {
        LOGGER.info(ioe.getMessage());
    }
    finally
    {
        try {
            // Logout
            ftpClient.logout();
            // Disconnect
            ftpClient.disconnect();
        } catch (IOException e) {
            LOGGER.info(e.getMessage());
        }
    }
}

你能更新代码吗?代码中似乎缺少右括号。谢谢。当你无法连接到ftp时,请退出系统?使用OrganizationLocalServiceUtil听起来像是在Liferay中运行的,Liferay在应用程序服务器中运行-处理System.exit的应用程序级问题??真正地不是你的浏览器说明了由于这个原因而关闭的连接,对吗?