title: How to upload file with curl on sftp server
body: <p>This code</p>
  
  <pre><code>$user = 'user';
  $pass = 'password';
  $filename = 'text.txt';
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  $ch = curl_init();
  $localfile = 'text.txt';
  $fp = fopen($localfile, 'r');
  curl_setopt($ch, CURLOPT_URL, 'sftp://$user:$pass@myserver.com/upload/$filename');
  curl_setopt($ch, CURLOPT_UPLOAD, 1);
  curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
  curl_setopt($ch, CURLOPT_INFILE, $fp);
  curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
  curl_exec ($ch);
  $error_no = curl_errno($ch);
  curl_close ($ch);
  if ($error_no == 0) {
          $error = 'File uploaded succesfully.';
  } else {
          $error = 'File upload error.';
  }
  echo $error.' '.$error_no;
  </code></pre>
  
  <p>gives me this error:</p>
  
  <blockquote>
    <p>File upload error. 7 ( Failed to write file to disk )</p>
  </blockquote>
  
  <p>My requirement is simple, I just need to upload <code>text.txt</code> file on live server using curl.</p>