如何使用ftp将大型文件30-50 mb文件大小上传到服务器

时间:2015-08-07 11:56:45

标签: java file-upload ftp file-handling

我正在开发一个像drop box一样工作的java应用程序。但是当我发送一个超过5-10mb的文件时,他们不会上传它并显示一些异常。上传文件我使用ftp.and设置缓冲区大小但是它不能正常工作你能不知道如何增加缓冲区的大小以及如何将大型文件上传到服务器

  public void uploadtxtFile(collectinfo myobj,String localFileFullName, String fileName, String hostDir)
            throws Exception {
        //int index = hostDir.lastIndexOf('/');
        //new
        long size = 0;
        long start = System.currentTimeMillis();
        long end = start + 10*1000; // 60 seconds * 1000 ms/sec
         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 ;

                    //  ftpclient =DBConnection.connect();
                 try{
                    //to set buffer size
                     logger.error("Replay of the ftp store file is 1111"+  ftpclient.getReplyCode());

                             ftpclient.setBufferSize(1048576);

                     while (System.currentTimeMillis() < end)
                        {
                          // run
                        }
                     ftpclient.enterLocalPassiveMode();
                     while (System.currentTimeMillis() < end)
                     {
                           // run
                     }
                       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());

                   }  else{
                       logger.error("here server timeout error is get");//new

                             bis = new BufferedInputStream(input);
                       logger.error("Replay of the ftp  not store file 6666"+  ftpclient.getReplyCode());
                       ftpclient= DBConnection.connect();
                       logger.error("Replay of the ftp store file is new connection 9999"+  ftpclient.getReplyCode());
                       ftpclient.enterLocalPassiveMode();
                       bool =  ftpclient.storeFile(hostDir, bis);

                   }
                 }catch(Exception ex){
                     logger.error("the problem into the null pointer "+  ex);
                     BackgroundService.pendingQueue.add(myobj); 
                     } 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.");
            }
        }
    }

以及显示的例外情况

1.org.apache.commons.net.io.CopyStreamException: IOException caught whilecopying.
2.  java.net.ConnectException: Connection timed out: connect

在小文件大小上传时间也显示异常,但文件将上传时间 任何人都可以帮我解决这个问题

0 个答案:

没有答案