java - retrieveFile throws an org.apache.commons.net.io.CopyStreamException: IOException caught while copying -
i try download couple of files (314) remote ftp-server java program. when call "retrievefile" function apache commons program stops given exception in subject.
tried enter passive mode no effect.
main[] calls function after init tasks. here code:
private static void transferfiles() throws socketexception, ioexception { string strcurrentfilename=null; ftpclient ftpc=new ftpclient(); import.fmitglieder=file.createtempfile("member", ".xls"); import.fkontakte=file.createtempfile("contacts", ".xls"); fileoutputstream fosmitgliederwriter=new fileoutputstream(import.fmitglieder), foskontaktewriter=new fileoutputstream(import.fkontakte); boolean bfiletypechange=true; ftpfile[] ftpfilearray=null; long lstarttime=0; int irunner=0; if(import.connecttoftpserver(ftpc)) { bfiletypechange=ftpc.setfiletype(ftp.binary_file_type); if(loger.isdebugenabled()) loger.debug("filetypechange result: " + bfiletypechange); ftpfilearray=ftpc.listfiles(); if(loger.isdebugenabled()) loger.debug("am server befinden sich " + ftpfilearray.length + " files."); while(irunner < ftpfilearray.length) { strcurrentfilename=ftpfilearray[irunner].getname(); if(strcurrentfilename.equalsignorecase("pictures") && ftpfilearray[irunner].isdirectory()) { ftpfile[] ftppicturefilearray=null; int ipicturerunner=0; string strcurrentpicturename=null; file ftemppicture=null; fileoutputstream fospicture=null; ftpc.changeworkingdirectory("pictures"); ftppicturefilearray=ftpc.listfiles(); if(loger.isdebugenabled()) loger.debug("am server befinden sich " + ftppicturefilearray.length + " bilder."); while(ipicturerunner < ftppicturefilearray.length) { strcurrentpicturename=ftppicturefilearray[ipicturerunner].getname(); if(loger.isdebugenabled()) loger.debug("bild zum transfer: " + strcurrentpicturename); ftemppicture=file.createtempfile(strcurrentpicturename, null); if(loger.isdebugenabled()) loger.debug("tempfile erzeugt mit namen: " + ftemppicture.getname()); fospicture=new fileoutputstream(ftemppicture); lstarttime=system.currenttimemillis(); if(loger.isdebugenabled()) loger.debug("fileoutputstream erzeugt, starte retrievefile!"); //the next line 1 throws exception ftpc.retrievefile(strcurrentpicturename, fospicture); if(loger.isdebugenabled()) loger.debug("bilddatei übertragen mit namen: " + strcurrentpicturename + " auf lokalen namen: " + ftemppicture.getname() + " in " + (system.currenttimemillis() - lstarttime) + " msecs"); fospicture.close(); hmpicturetransfer.put(strcurrentpicturename, ftemppicture.getcanonicalpath()); //just remember files transfered ipicturerunner++; } ftpc.changetoparentdirectory(); } else if { //handle other stuff not interest in here } else loger.warn("unerwartetes file server: " + strcurrentfilename); irunner++; } fosmitgliederwriter.close(); foskontaktewriter.close(); ftpc.logout(); ftpc.disconnect(); if(loger.isdebugenabled()) loger.debug("output-streams geschlossen und verbindung zu ftp-server getrennt!"); if(ftpfilearray.length < 1) sbinfoemail.append("am server war keine datei zur abholung hinterlegt!" + import.strnewline); } else { import.sbmailexception.append("authentifizierung zum server " + import._server + " mit login: " + import._login + " und passwort: " + import._pwd + " war nicht erfolgreich!" + import.strnewline); } } private static boolean connecttoftpserver(ftpclient p_ftpclient) { p_ftpclient.setdatatimeout(import.dataconnectiontimeout.intvalue()); //gets value via property file set to: 30000 try { p_ftpclient.connect(import.server); p_ftpclient.enterlocalpassivemode(); if(loger.isdebugenabled()) loger.debug("server response: " + p_ftpclient.getreplystring()); return p_ftpclient.login(login, wpwd); } catch(socketexception e) { loger.error("fehler bei ftp-verbindung zum server!", e); import.sbmailexception.append("socket fehler bei aufbau der ftp-verbindung!" + import.strnewline); } catch(ioexception e) { loger.error("io-fehler bei ftp-verbindung zum server!", e); import.sbmailexception.append("io-fehler bei aufbau der ftp-verbindung!" + import.strnewline); } return false; } the reported exception in logfile looks like:
org.apache.commons.net.io.copystreamexception: ioexception caught while copying. @ org.apache.commons.net.io.util.copystream(util.java:135) @ org.apache.commons.net.ftp.ftpclient._retrievefile(ftpclient.java:1800) @ org.apache.commons.net.ftp.ftpclient.retrievefile(ftpclient.java:1769) @ ag.oase.gastrodb.jobs.wkkimport.transferfiles(wkkimport.java:275) @ ag.oase.gastrodb.jobs.wkkimport.main(wkkimport.java:160) caused by: java.net.socketexception: connection reset @ java.net.socketinputstream.read(socketinputstream.java:168) @ java.io.bufferedinputstream.read1(bufferedinputstream.java:256) @ java.io.bufferedinputstream.read(bufferedinputstream.java:317) @ java.io.filterinputstream.read(filterinputstream.java:90) @ org.apache.commons.net.io.util.copystream(util.java:101) ... 4 more i have no clue how avoid problem. tried changing idle timeout, active passive transfer mode, binary or ascii mode (which not idea picture files). unfortunately exception still thrown. when transfer files filezilla there no problem. can exclude server makes mistake.
can me?
thanks in advance rené
to track problem down changed method retrieve file
ftpc.retrievefile(strcurrentpicturename, fospicture); to
int icount; byte[] content=new byte[4096]; inputstream iscontent=null; iscontent=ftpc.retrievefilestream(strcurrentpicturename); while((icount=iscontent.read(content))!=-1) { if(icount>0 && loger.isdebugenabled()) loger.debug(icount+" chars read); } ftpc.completependingcommand(); iscontent.close(); now behavior is, system starts read stream, very slowy. here output of logfile:
2013-04-18 19:18:00,298 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:05,329 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:10,377 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:15,392 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:20,314 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:25,455 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:30,486 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:35,408 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read 2013-04-18 19:18:52,361 [main] debug ag.oase.gastrodb.jobs.wkkimport - 1144 chars read as can see, 1144 bytes took 5 sec read calculates down speed of 0,22 kb/s not normal. when open command ftp client transfer same file same user same server on same client speed shows: 331127 bytes received in 0.11 secs (2967.1 kb/s)
so bottleneck somewhere resides in java or commons.net package? or in code :-)
i appreciate every help.
in advance rené
Comments
Post a Comment