You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Goldstein Lyor (JIRA)" <ji...@apache.org> on 2017/08/23 17:23:00 UTC

[jira] [Commented] (SSHD-765) SFTP client fails to retrieve a binary file using an InputStream

    [ https://issues.apache.org/jira/browse/SSHD-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16138684#comment-16138684 ] 

Goldstein Lyor commented on SSHD-765:
-------------------------------------

Indeed a bug (which I am fixing) - as a temporary workaround until we release this perhaps you can wrap the SFTP input stream inside a {{BufferedInputStream}} so that reading one byte is never invoked:
{code:java}
try (InputStream sftpStream = sftp.read(...);
    InputStream wrapper = new BufferedInputStream(sftpStream);
    InputStream zipped = new GZipInputStream(wrapper)) {

    ....read from zipped stream...
}
{code}

> SFTP client fails to retrieve a binary file using an InputStream
> ----------------------------------------------------------------
>
>                 Key: SSHD-765
>                 URL: https://issues.apache.org/jira/browse/SSHD-765
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 1.6.0
>            Reporter: Michael Binder
>            Assignee: Goldstein Lyor
>
> The SFTP client fails to retrieve a binary file from an SFTP server using the InputStream returned by the {{SftpClient.read (String)}} method.
> In my case the binary file was actually a gzipped XML file. So I wrapped the returned InputStream in a {{java.util.zip.GZIPInputStream}} object. When reading from the stream I received an IOException with following message:
> "org.apache.sshd.client.subsystem.sftp.SftpInputStreamWithChannel.read() returned value out of range -1..255: -117".
> I think that this method violates the contract given in {{java.io.InputStream}}: "The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned."
> After I patched line 130 in SftpInputStreamWithChannel.java to
> {code:java}
>             return bb[0] & 0xFF;
> {code}
> retrieving the file seemed to have worked fine.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)