java - FTP download stops at file #146 -


i wrote class (from examples) download header of files contained in remote ftp folder. works well, when approaches download file #146 stops nullpointexception. file #146 exists , can download single file actually.

in method remotepathlong contains remote folders written in single line , spaced space character.

public void downloadheader(string remotepathlong, string destpath, int bytes) {      string remotepath;     ftpfile[] filelist;     string[] filenamelist;      ftpclient ftpclient = new ftpclient();     try {         ftpclient.connect(server);         ftpclient.login(user, pass);         ftpclient.enterlocalpassivemode();         ftpclient.setfiletype(ftp.binary_file_type);          int indice = 0;         int ip = 1;         file downloadfile;         string destfile;         string remotefile;         byte[] bytesarray;         int bytesread = -1;         while ((remotepath = getpath(remotepathlong, ip)) != null) {             system.out.println("loading file list server.....");             filenamelist = ftpclient.listnames(remotepath);             (string file : filenamelist) {                 indice += 1;                 system.out.println(indice + " - downloading: " + file);                  //select files                 destfile = destpath.concat(file);                  downloadfile = new file(destfile);                 outputstream = new bufferedoutputstream(new fileoutputstream(downloadfile));                  //download remote file (from ftp)                 remotefile = remotepath.concat(file);                  inputstream = ftpclient.retrievefilestream(remotefile);                 bytesarray = new byte[bytes];                 bytesread = inputstream.read(bytesarray);                 outputstream.write(bytesarray);                  //save file                  outputstream.close();                 inputstream.close();                 ip += 1;             }         }      } catch (ioexception ex) {     } final{         try {             if (ftpclient.isconnected()) {                 ftpclient.logout();                 ftpclient.disconnect();             }         }         catch (ioexception ex1) {             system.out.println("error: " + ex1.getmessage());         } } 

when reaches bytesread = inputstream.read(bytesarray), @ iteration #146 gives error. if @ same iteration reinitialize connection works. have suggestion please?

it possible connection times out due network traffic or file size happens 146th. can print 146th file name , check size. can increase ftp connection timeout period

ftpclient.setcontrolkeepalivetimeout(300); // set timeout 5 minutes 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -