java - Using JSch ChannelSftp : What file handling is required while calling ChannelSftp.cd(...) and ls(..) methods? -
below code, channel object initialized : (sftp internal file. let's assume changedirectory() method part of class. )
private void changedirectory() throws sftpexception { // jsch initializes session session = jsch.getsession( "remote-username", "remote-host" ); channel channel = session.openchannel( "sftp" ); channel.connect(); channelsftp sftpchannel = (channelsftp) channel; // remotedirectory initialized sftpchannel.cd(remotedirectory); }
when code being executed, getting errors in below format :
caused by: 4: @ com.jcraft.jsch.channelsftp.cd(channelsftp.java:359) @ com.dclear.cmn.cms.net.sftp.changedirectory(sftp.java:139) @ com.dclear.cmn.cms.net.sftp.receivefile(sftp.java:80) ... 7 more caused by: java.lang.indexoutofboundsexception @ java.io.pipedinputstream.read(pipedinputstream.java:372) @ com.jcraft.jsch.channelsftp.fill(channelsftp.java:2869) @ com.jcraft.jsch.channelsftp.fill(channelsftp.java:2861) @ com.jcraft.jsch.channelsftp._realpath(channelsftp.java:2319) @ com.jcraft.jsch.channelsftp.cd(channelsftp.java:342) ... 9 more
however when dig deep it, understand avoid indexoutofboundsexception have take care of following :
len negative, or len greater b.length - off :
b - buffer data read. off - start offset in destination array b len - maximum number of bytes read.
but, internal code..how keep check before calling cd(..) method on file?? have file location & filesize.
for of files getting below exception :
exception: failed directory listing in sftp protocol.... 4: @ com.jcraft.jsch.channelsftp._stat(channelsftp.java:2187) @ com.jcraft.jsch.channelsftp._stat(channelsftp.java:2202) @ com.jcraft.jsch.channelsftp.ls(channelsftp.java:1566) @ com.jcraft.jsch.channelsftp.ls(channelsftp.java:1527)
which comes when code calls :
list<lsentry> ls = sftpchannel.ls(remotedirectory);
any inputs avoid these random errors? sure because file handling missed , behaving differently different files?
fyi jsch version : jsch\1.5\jsch-0.1.50.jar channelsftp (version 1.4 : 48.0, super bit)
Can you share code snippet to resolve indexoutofboundsexception on channelsftp.cd method
ReplyDelete