在上传文件时,他们显示连接未打开如何解决

时间:2015-08-06 10:11:28

标签: java exception ftp

我在java应用程序中工作,我正在使用ftp发送文件。 但是当我发送20-30文件时,它的show异常即连接未打开 并且文件不发送可以任何人帮助我。我用来上传文件的cade在

之下
public void uploadtxtFile(collectinfo myobj,String localFileFullName, String fileName, String hostDir)
            throws Exception {
       FTPClient ftpclient= DBConnection.connect();
        File file = new File(localFileFullName);
        if (!(file.isDirectory())) {
            if (file.exists()) {
                FileInputStream input = null;
                 BufferedInputStream bis=null;
                try {
                    input = new FileInputStream(new File(localFileFullName));
                    if (input != null) {

                        hostDir = hostDir.replaceAll("//", "/");
                       logger.info("uploading host dir : " + hostDir);


                       boolean bool =false ;


                       logger.error("Replay of the ftp store file is 1111"+  ftpclient.getReplyCode());
                 try{
                    ftpclient.setBufferSize(1048576);
                     ftpclient.enterLocalPassiveMode();
                       logger.error("Replay of the ftp store file is 2222"+  ftpclient.getReplyCode());
                   if(  ftpclient.isConnected()){                   
                    //  here server timeout error is get
                       logger.error("here server timeout error is get");//new
                       bis = new BufferedInputStream(input);
                       logger.error("Replay of the ftp store file is 3333"+  ftpclient.getReplyCode());
                       bool =  ftpclient.storeFile(hostDir, bis);



                }  else{
                       logger.error("here server timeout error is get");//new
                             bis = new BufferedInputStream(input);
                       logger.error("Replay of the ftp store file is 6666"+  ftpclient.getReplyCode());
                       ftpclient.enterLocalPassiveMode();
                       bool =  ftpclient.storeFile(hostDir, bis);


                   }}finally{
                       bis.close();
                    input.close();


                   }

                   logger.error("Replay of the ftp store file is 4444 "+  ftpclient.getReplyCode());

                  if (bool) {
                            logger.info("Success uploading file on host dir :"+hostDir);
                        } else {

                             logger.error("file  not uploaded.");
                             BackgroundService.pendingQueue.add(myobj); 
                        }

                    } else {
                         logger.error("uploading file input null.");
             }
           } catch(Exception ex)
                {
                     logger.error("Error in connection ="+ex);
                    BackgroundService.pendingQueue.add(myobj);

                }finally {
                     ftpclient.logout();
                     ftpclient.disconnect();
              }

            } else {
                  logger.info("uploading file is not exists.");
            }
        }
    }

进入该DBConnection是一个返回FTPclient obj

的类

0 个答案:

没有答案