title: PHP SSH2 operations failing when attempting to upload file to server
body: <p>I am currently struggling with using the SSH2 built-in libraries for PHP (running version 5.5). I am trying to upload a file to an SFTP server as the title states however I keep getting a "stream operation failed" error message. </p>
  
  <p>After attempting to debug the code itself the connection works, the sftp resource is assigned an ID correctly, however when fopen is called for writing the file directly to the remote server it fails. </p>
  
  <pre><code>// open Live environment if we are not in dev
  $connection = ssh2_connect($this-&gt;_settings['source_host'], 22);
  $authSuccess = ssh2_auth_password($connection, $this-  &gt;_settings['source_user'], $this-&gt;_settings['source_password']);
  $sftp = ssh2_sftp($connection);
  </code></pre>
  
  <p>And finally the fopen() call: </p>
  
  <pre><code>if($operation == 'export') {
      $handle = fopen("ssh2.sftp://".$sftp."/remotecopy/IN/".$filename, $mode);
  }
  </code></pre>
  
  <p>I added debug messages in my own code to verify if the data from the _settings array is also used correctly and it is, however I can't explain the stream error.</p>
  
  <pre><code>Message:  fopen(): Unable to open ssh2.sftp://Resource id #173/PATH GOES HERE/filename.xxx on remote host
  
  Message:  fopen(ssh2.sftp://Resource id #173/PATH GOES HERE/filename.xxx): failed to open stream: operation failed
  </code></pre>
  
  <p>As a note the file does not exist on the remote host but according to my knowledge 'w' mode in PHP fopen() should create the file if it does not exist.</p>
  
  <p>I can't use the other PHP library as our whole project uses the builtin ssh2 libraries and the person in charged told me to not use it as it works fine everywhere else. </p>