apache poi - SFTP: IOException while reading a file with java -


i using com.jcraft.jsch library read .xls files sftp server. following code connect server.

    session = jsch.getsession(username, host);     session.setconfig("stricthostkeychecking", "no");     session.setpassword(password);     session.connect();     sftpchannel = (channelsftp) session.openchannel("sftp");     sftpchannel.connect(); 

i using sftpchannel.get(file) retrieve inputstream file. inputstream used instantiate xssfworkbook shown below:

xssfworkbook workbook = new xssfworkbook(in); 

problem 1:

when run app, seems stuck on above line time (say 5 minutes) , throws java.io.ioexception: pipe closed error. xls file trying read 800kb , works fine when run local machine.

problem 2:

the app designed process files sequentially. so, if first file fails ioe, rest of files fail connection timed out. prevent this, put below code check , re-connect:

if(null == session || !session.isconnected()){         log.debug("session not connected/timed out. creating new session");         opensftpsession();         log.debug("new session created");     } //opensftpsession() code create new session explained in beginning of question. 

when code gets executed, following exception gets thrown:

java.io.ioexception: error: 4: requestqueue: unknown request id 1028332337     @ com.jcraft.jsch.channelsftp$2.read(channelsftp.java:1407)     @ java.io.filterinputstream.read(filterinputstream.java:133)     @ java.io.pushbackinputstream.read(pushbackinputstream.java:186) //more lines 

edit : code retrieve input stream

public inputstream getinputstream(string folder, string file) throws exception{     sftpchannel.cd(root + folder);     log.debug("current directory:" + sftpchannel.pwd());     log.debug("file :" + folder + " " + file);     return sftpchannel.get(file); } 

can please me on this? believe alternate approach prevent timeout download file in temp directory , process. however, don't want that.

thanks in advance.

have checked see whether approach describe (download temp file) works? verify inputstream ok.. how long take download local file on connection?

if don't want manage temp file pull byte[] in memory, long don't have scale more 800kbs.. use apache commons such:

inputstream in = sftpchannel.get(file); byte[] inbytes = org.apache.commons.io.ioutils.tobytearray(in) bytearrayinputstream inbytestream = new bytearrayinputstream(inbytes) xssfworkbook workbook = new xssfworkbook(inbytestream); 

as request id, looks old session/channel still trying read no longer able to. maybe aren't closing out session/channel properly. opensftpsession() code looks overwriting references without shutting them down.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -