title: "Permission denied" when opening file for writting second time
body: <p>I am transferring a file from Linux to windows using library libssh in SFTP mode using C++ on Windows.</p>
  
  <p>I am able to create a file on Windows side and write in it for once using this program:</p>
  
  <pre><code>int sftp_read_sync(ssh_session session, sftp_session sftp)
  {
    int access_type;
    sftp_file file;
    char* buffer[MAX_XFER_BUF_SIZE];
    int nbytes, nwritten, rc;
    int fd;
    access_type = O_RDONLY;
    file = sftp_open(sftp, "/root/bel1.txt",
                     access_type, 0);
    if (file == NULL) {
        fprintf(stderr, "Can't open file for reading: %s\n",
                ssh_get_error(session));
        return SSH_ERROR;
    }
    fd = open("C:\\Users\\Wipro\\Desktop\\bel6.txt", O_WRONLY | O_CREAT  | O_TRUNC);
    if (fd &lt; 0) {
        fprintf(stderr, "Can't open file for writing: %s\n",
                strerror(errno));
        return SSH_ERROR;
    }
    for (;;) {
        nbytes = sftp_read(file, buffer, sizeof(buffer));
        if (nbytes == 0) {
            break; // EOF
        } else if (nbytes &lt; 0) {
            fprintf(stderr, "Error while reading file: %s\n",
                    ssh_get_error(session));
            sftp_close(file);
            return SSH_ERROR;
        }
        nwritten = write(fd, buffer, nbytes);
        if (nwritten != nbytes) {
            fprintf(stderr, "Error writing: %s\n",
                    strerror(errno));
            sftp_close(file);
            return SSH_ERROR;
        }
    }
    rc = sftp_close(file);
    if (rc != SSH_OK) {
        fprintf(stderr, "Can't close the read file: %s\n",
                ssh_get_error(session));
        return rc;
    }
    return SSH_OK;
  }
  </code></pre>
  
  <p>On running this same program again, I'm getting an error:</p>
  
  <blockquote>
    <p>Can't open file for writing: Permission denied</p>
  </blockquote>
  
  <p>The file created is not having a permission to rewrite in it.</p>
  
  <p>How can I correct this?</p>