Transferring multiple files from ftps server to Liferay Portal -


we have client ftp server uploads multiple number of pdf files in /dev directory. pattern of pdf files [organaization_name]_cr.pdf . retrieving these files , uploading our liferay document library based on [organaization_name].

we facing issue while retrieving multiple files using single ftp connection. first time retrieves list of files of current directory (/dev) , uploads in liferay document library. when trying retrieve second file, returns length of files 0 , throwing error exception sending alert: java.net.socketexception: connection reset peer: socket write error: connection closed without indication.

please refer below code.

public static void importreports() {     inputstream = null;      system.setproperty("javax.net.debug", "ssl");      ftpsclient ftpclient = new ftpsclient();     try      {              // store file on host              ftpclient.addprotocolcommandlistener(new printcommandlistener(new printwriter(system.out)));            // connect host             ftpclient.connect(hostname);             int reply = ftpclient.getreplycode();             if (!ftpreply.ispositivecompletion(reply)) {                 ftpclient.disconnect();                 system.exit(1);             }             if (!ftpclient.login(loginname), portletprops.get(password))) {                 ftpclient.logout();                 system.exit(1);             }             // set protection buffer size             ftpclient.execpbsz(0);             // set data channel protection private             ftpclient.execprot("p");         try{               list<organization> orglist = organizationlocalserviceutil.getorganizations(-1, -1);               (organization organization : orglist) {                                 string folderpath ="/dev";                                 string ftpfilename = organization.getname();                                 string ftpfilepath = folderpath+stringpool.forward_slash+ftpfilename;                                 ftpclient.changeworkingdirectory(folderpath);                                  // enter local passive mode                                 ftpclient.enterlocalpassivemode();                                 ftpclient.setremoteverificationenabled(false);                                 ftpfile[] files = ftpclient.listfiles(folderpath);                                 for(ftpfile file : files)                                 {                                     if(file.isfile() && file.getsize() > 0 && file.getname().equalsignorecase(ftpfilename))                                     {                                          try{                                             = ftpclient.retrievefilestream(ftpfilepath);                                             if (validator.isnotnull(is)) {                                               ftpclient.completependingcommand();                                         }catch(socketexception se)                                         {                                             logger.info("socketexception  :"+se.getmessage());                                           }                                     }                                 }                              }                 // logout                 ftpclient.logout();                 // disconnect                 ftpclient.disconnect();         }         catch(portalexception e)         {             logger.info(e.getmessage());         } catch (systemexception e) {             logger.info(e.getmessage());         }     } catch (ioexception ioe) {         logger.info(ioe.getmessage());     }         {         try {             // logout             ftpclient.logout();             // disconnect             ftpclient.disconnect();         } catch (ioexception e) {             logger.info(e.getmessage());         }     } } 


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -