Why setControlKeepAliveTimeout does not work with retrieveFileStream and what is the alternative for it?
<p>I have written a code using org.apache.commons.net.ftp.FTPClient and used retrievefilestream function. In my program i am trying to download list of files one after another.But in case i download a big file then i try to download another file after it the connection goes off but if the file are of smaller size the download goes smooth so i got a solution of setControlKeepAliveTimeout but in the documentation of package only its written as note that:</p>

<p><strong>NOTE:</strong> this does not apply to the methods where the user is responsible for writing or reading the data stream, i.e. retrieveFileStream(String) , storeFileStream(String) and the other xxxFileStream methods </p>

<p>Below is given functions to download file</p>

<pre><code>public static void read() throws IOException {
                int count = 0;
                InputStream is = null;
                byte[] buffer=new byte[100000];
                File root = Environment.getExternalStorageDirectory();
                File ftd=new File(root.getAbsolutePath()+"/filetodownload.txt");
                if(ftp.listNames(path)!=null){
                File videoFile = new File(root.getAbsolutePath()+"/media/"+ xmlfiles[file_no]);     //File name should be taken from Server side
                FileOutputStream out = new FileOutputStream(videoFile,true);


            try {
                        ftp.setRestartOffset(position);
                        is = ftp.retrieveFileStream(path);
                        int eflag=0;
                        while (true) {
                            try{
                                    if(eflag==1){
                                        getFtpCon();
                                        //ftp.setControlKeepAliveTimeout(100);
                                        //ftp.setControlKeepAliveReplyTimeout(300000);
                                        ftp.setRestartOffset(position);
                                        is=ftp.retrieveFileStream(path);
                                        eflag=0;
                                    }
                                    count = is.read(buffer);
                                    if(count == -1)
                                    {
                                        break;
                                    }
                                    if(count&gt;=0){
                                        out.write(buffer,0,count);
                                        position += count;
                                    }
                                    else                
                                    {
                                        break;
                                    }

                            }
                            catch(Exception ex)
                            {
                                eflag=1;
                                ftp.disconnect();
                                ftp = new FTPClient();
                                ftp.getStatus();
                                ftp.enterLocalActiveMode();
                                continue;
                            }

                        }
                        delLine(ftd);               //deleting downloaded file from log
            }

            catch (Exception e) {
                    writeErrorFile("Error While Downloading File: "+e.getMessage());
            }

            finally {
                try{
                        if (is != null) {
                            is.close();
                        }
                        out.close();
                        ftp.completePendingCommand();
                }catch(Exception exx)
                {

                }
            }

        }
    }
</code></pre>

<p>Please Reply as soon as possible</p>
