title: Download file from SFTP server with libssh and write it to ofstream by using C++?
body: <p>I wrote the following code from <a href="http://api.libssh.org/master/libssh_tutor_sftp.html" rel="nofollow noreferrer">this</a>. </p>
  
  <pre><code>#define MAX_XFER_BUF_SIZE 16384
  int main()
  {
      char buffer[MAX_XFER_BUF_SIZE];
  
        //..some content
       access_type = O_RDONLY;
       sftp_file file = sftp_open(sftp, "/home/ra/Desktop/sami/s.txt", access_type, 0);
       ofstream fin("C:/Users/s.txt", ios::binary | ios::in | std::ofstream::out | std::ofstream::app);
  
       nbytes = sftp_read(file, buffer, sizeof(buffer));
       fin.write(buffer, sizeof(buffer));
  </code></pre>
  
  <p>But the buffer maximum size is predefined. So it only works for small files. I want to get the SFTP file size which size is much bigger. For that I need to send the data as chunks by append mode.</p>
  
  <hr>
  
  <pre><code>for (int i=0;i&lt;sizeof(buffer);i++)
  {
      fin.write(buffer, buffer[i]);
  }
  </code></pre>
  
  <p>I went through <a href="https://stackoverflow.com/questions/13691520/how-to-copy-a-file-in-c-c-with-libssh-and-sftp?rq=1">this answer</a>, but i'm stuck in this > How can i solve this issue.</p>