title: Unable to create folder recursively in remote server using PHP
body: <p>I was trying to create directory in a remote SFTP server using PHP.
  But then always failed to create.</p>
  
  <p>Following is what I tried.</p>
  
  <pre><code>$connection = ssh2_connect($server, 22);
  $path = "images/vehicle/car/sports/";
  if(ssh2_auth_password($connection, $username, $password)){
      echo "connected\n";
      $sftp = ssh2_sftp($connection);
      if (file_exists('ssh2.sftp://' . $sftp . '/' . $path)) {
          echo "present\n";
      } else {
          ssh2_sftp_mkdir($sftp, $path);
          $contents = file_get_contents('car.jpeg');
          file_put_contents("ssh2.sftp://$sftp/$path/car.jpeg", $contents);
      }
  } else {
      echo "connection failed\n";
  }
  </code></pre>
  
  <p>Ques 1. Am unable to create directory. Is there any issue in this script?</p>
  
  <p>Ques 2. Am able to create each folder one by one like this,</p>
  
  <pre><code>ssh2_sftp_mkdir($sftp, '/images');
  ssh2_sftp_mkdir($sftp, '/images/vehicle');
  ssh2_sftp_mkdir($sftp, '/images/vehicle/car');
  </code></pre>
  
  <p>So is this anything permission related issue?</p>
  
  <p>Ques 3. file_exists condition always failing. Is there another method to check directory existing or not in remote server?</p>
  
  <p>Thanks</p>