title: Libssh2 stop reading large file
body: <p>I need to read some files via ssh, but when I loop on the file for reading... it stops.
  <br>In my Cargo.toml I have this dependency:</p>
  <pre><code>[dependencies]
  ssh2 = &quot;0.8&quot;
  </code></pre>
  <p>It depends from libssh2.
  <br>Code is more complex, but I managed to reproduce the problem with this dirty code:</p>
  <pre><code>  use std::fs::File;
    use std::io::Read;
    use std::io::Write;
    #[allow(unused_imports)]
    use std::io::Error;
    use std::net::TcpStream;
    use ssh2::Session;
    use std::path::Path;
    use std::io::prelude::*;
  
    fn main() {
        println!(&quot;Parto!&quot;);
  
        let tcp = TcpStream::connect(&quot;myhost:22&quot;).unwrap();
        let mut sess = Session::new().unwrap();
        sess.set_tcp_stream(tcp);
        sess.handshake().unwrap();
        sess.userauth_password(&quot;user&quot;, &quot;password&quot;).unwrap();
        assert!(sess.authenticated());
  
        let (mut remote_file, stat) = sess.scp_recv(Path::new(&quot;/home/pi/dbeaver.exe&quot;)).unwrap();
        println!(&quot;remote file size: {}&quot;, stat.size());
        let mut buf: Vec&lt;u8&gt; = vec![0;1000];
  
        loop {
            let read_bytes = remote_file.read(&amp;mut buf).unwrap();
            println!(&quot;Read bytes: {}.&quot;, read_bytes);
            if read_bytes &lt; 1000 {
                break;
            }
        } //ending loop
    }
  </code></pre>
  <p>I tested both on Windows 10 and Linux Debian. The problem is always there when the file is more then few KB this read:</p>
  <pre><code>let read_bytes = remote_file.read(&amp;mut buf).unwrap();
  </code></pre>
  <p>reads less than buffer size (but the file is not ended).
  <br>Tested with both binary or asci files.</p>
  <p>No errors, it just stop reading. Odd thing: it sometimes stop at 8 MB, sometimes at 16 KB. With the same file and host involved...</p>
  <p>Where do I need to dig or what I need to check?</p>