linux环境下下 FTPClient.retrieveFile() 下载稍大一点的文件就卡死了

FTPClient f = new FTPClient();   
    OutputStream out = null;
        f.connect(url,port);
          f.login(username, password);
          f.enterLocalPassiveMode();   //被动

         f.setControlEncoding("GBK");  
         f.setFileType(FTPClient.BINARY_FILE_TYPE);  
          f.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
        //f.setBufferSize(524288);
        //f.setSoTimeout(300000);     //  时间
        //f.setDataTimeout(300000);   //  时间
        f.changeWorkingDirectory(f.printWorkingDirectory()+ remotePath);   

        FTPListParseEngine engine = f.initiateListParsing(remotePath);
         FTPFile[] files = null;
        while (engine.hasNext()) {
            files = engine.getNext(25);  // "page size" you want
            for(FTPFile ff:files){   
                 if(ff.getName().equals(fileName)){   
                     File outfile = new File(localPath+"/"+newfilename);    
                     out = new BufferedOutputStream(new FileOutputStream(outfile));

                   logger.info(remotePath+"/"+ff.getName());
                    logger.info(remotePath+"/"+new String(ff.getName().getBytes("GBK"),"ISO-8859-1"));
                    boolean is = f.retrieveFile(remotePath+"/"+new String(ff.getName().getBytes("GBK"),"ISO-8859-1"), out);  

                     out.flush();
                     out.close(); 

                 }   
            }   

            i++;
        }
        f.logout();   


        下载一个 1kb的文件可以正常下载,说明权限是没问题的,9kb的文件就下载不了了,环境是linux+tomcat,   求教        
            另: windows环境下是正常的

下载大小应该可以设置吧

在lunix上要用InputStream input = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"),"ISO-8859-1"));
重要的是retrieveFileStream这个方法,而且前边要加ftp.enterLocalPassiveMode();

在windows系统上边发的服务要用 ftpClient.retrieveFile(new String(ff.getName().getBytes("GBK"),"ISO-8859-1"), out);
重要的是retrieveFile这个方法,前边不需要加ftp.enterLocalPassiveMode();

具体原因还是不太清除,可能是流的传输方式不同导致。

亲测加上ftp.enterLocalPassiveMode();完美解决