1

During opening the file in this way:

RemoteFile remoteFile = sftpClient.open(path)

I've faced with following error with stacktrace:

java.lang.ArrayIndexOutOfBoundsException: arraycopy: destination index -4 out of bounds for byte[256] at net.schmizz.sshj.common.Buffer.putRawBytes(Buffer.java:271) at net.schmizz.sshj.connection.channel.ChannelOutputStream$DataBuffer.write(ChannelOutputStream.java:64) at net.schmizz.sshj.connection.channel.ChannelOutputStream.write(ChannelOutputStream.java:141) at net.schmizz.sshj.connection.channel.ChannelOutputStream.write(ChannelOutputStream.java:131) at net.schmizz.sshj.sftp.SFTPEngine.transmit(SFTPEngine.java:292) at net.schmizz.sshj.sftp.SFTPEngine.request(SFTPEngine.java:130) at net.schmizz.sshj.sftp.SFTPEngine.doRequest(SFTPEngine.java:136) at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:141) at net.schmizz.sshj.sftp.SFTPClient.open(SFTPClient.java:68) at net.schmizz.sshj.sftp.SFTPClient.open(SFTPClient.java:73) at net.schmizz.sshj.sftp.SFTPClient.open(SFTPClient.java:78) at com.echovox.paidle.common.util.SftpUtil.getFileDataListFromZip(SftpUtil.java:86) at com.echovox.paidle.common.util.SftpUtil.lambda$getFileDataWithRetry$1(SftpUtil.java:139) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834)

I found 3 implementation of open method:

public RemoteFile open(String filename)

public RemoteFile open(String filename, Set<OpenMode> mode)

public RemoteFile open(String filename, Set<OpenMode> mode, FileAttributes attrs)

Is it possible to use somehow Set<OpenMode> mode and/or FileAttributes attrs to avoid this issue?

Taras Melnyk
  • 3,057
  • 3
  • 38
  • 34
  • Just making sure, you are trying to write file to remote server? Does the file exist there or are you creating a new one? You could try with this one: `sftpClient.open(path, EnumSet.of(OpenMode.WRITE, OpenMode.READ, OpenMode.CREAT, OpenMode.TRUNC));` If you are appending, try with `EnumSet.of(OpenMode.WRITE, OpenMode.READ, OpenMode.APPEND))` – Jokkeri Sep 13 '19 at 08:30
  • I have tried to do like you said but it does not work anyway – Taras Melnyk Sep 13 '19 at 08:38

0 Answers0