title: Upload file from local to SFTP via PHP SSH2
body: <p>I am trying to upload a local file from my Mac to SFTP via PHP. My code:</p>
  
  <pre><code>$connection = ssh2_connect($server, $port);
  if (ssh2_auth_password($connection, $username, $passwd)) {
  $sftp = ssh2_sftp($connection);
  echo "Connection successful, uploading file now..."."\n";
  $file = '/Users/petenaylor/Desktop/diamondexclusive.mp4';
  $contents = file_get_contents($file);
  file_put_contents("ssh2.sftp://{$sftp}/{$file}", $contents);
  } 
  else {
      echo "Unable to authenticate with server"."n";
  }
  </code></pre>
  
  <p>It connects as it should and I have checked that the local file location is correct, but the error messages I get are:</p>
  
  <p>Warning: file_get_contents(/Users/petenaylor/Desktop/diamondexclusive.mp4): failed to open stream: No such file or directory in /home/test.php on line 39</p>
  
  <p>Warning: file_put_contents(): Unable to open ssh2.sftp://Resource id #3//Users/petenaylor/Desktop/diamondexclusive.mp4 on remote host in /home/test.php on line 40</p>
  
  <p>Warning: file_put_contents(ssh2.sftp://Resource id #3//Users/petenaylor/Desktop/diamondexclusive.mp4): failed to open stream: operation failed in /home/test.php on line 40</p>
  
  <p>My log file from Filezilla:</p>
  
  <pre><code>Command:    put "/Users/petenaylor/Desktop/diamondexclusive.mp4" "diamondexclusive.mp4"
  Status:         local:/Users/petenaylor/Desktop/diamondexclusive.mp4 =&gt; remote:/home/myfarewellnote/web/diamondexclusive.mp4
  Trace:          FileTransferParseResponse(0)
  Trace:          CSftpControlSocket::ResetOperation(0)
  Trace:          CControlSocket::ResetOperation(0)
  Status:         File transfer successful, transferred 12,661,295 bytes in 111 seconds
  Status:         Retrieving directory listing of "/home/myfarewellnote/web"...
  Trace:          CSftpControlSocket::ParseSubcommandResult(0)
  Trace:          CSftpControlSocket::ListSubcommandResult()
  Trace:          CSftpControlSocket::SendNextCommand()
  Trace:          CSftpControlSocket::ListSend()
  Command:    ls
  Status:         Listing directory /home/myfarewellnote/web
  Trace:          CSftpControlSocket::ListParseResponse()
  Trace:          CSftpControlSocket::ResetOperation(0)
  Trace:          CControlSocket::ResetOperation(0)
  Status:         Directory listing of "/home/myfarewellnote/web" successful
  </code></pre>