title: Uploading a file using WebDav protocol from Unix
body: <p>I need to transfer a file from my Unix machine to a Windows machine. Problem is i can transfer a file already created on my machine via ftp from unix to any machine. also i can open webdav connection create new file and save it there. </p>
  
  <p>What i am unable to do is to write my code to upload my file fro my local location using webdav. </p>
  
  <p>i tried using pear client but due to lack of documentation, i am still not able to achieve the task . </p>
  
  <p>Here is my attempt:</p>
  
  <pre><code>include("/usr/share/pear/HTTP/WebDAV/Client.php");
  global $filename, $logger;
      try {
       /*   $client = new HTTP_WebDAV_Client();
          $user="username";
          $pass = "pwd";
          $dir = "webdavs://".$user.":".$pass."@hostname/";
          var_dump($client-&gt;stream_open($dir."test4.txt","w",null,$path));
          $client-&gt;stream_write("HELLO WORLD! , I am great ");
          $client-&gt;stream_close();
          $client-&gt;dir_opendir($dir,array());
          var_dump($client-&gt;dirfiles);
  
  
          $req =new HTTP_Request($dir);
          $req-&gt;setBasicAuth($user, $pass);
          $req-&gt;setMethod(HTTP_REQUEST_METHOD_POST);
  
          $result = $req-&gt;addFile('file_upload_field', $filename);
          if (PEAR::isError($result)) {
              echo $result-&gt;getMessage();
          } else {
  
              $response = $req-&gt;sendRequest();
  
              if (PEAR::isError($response)) {
                  echo $response-&gt;getMessage();
              } else {
                  echo $req-&gt;getResponseBody();
              }
          }*/
  
          $ftp_server = "hostname-ftp";
          //$ftp_server = "hostname-webdav";
          $connection = ftp_connect($ftp_server);
          ftp_login($connection, 'user', 'pwd);
          ftp_put($connection, $filename, $filename, FTP_BINARY);
          unlink($filename);
      } catch(Exception $e){
          $message = "There was a problem while uploading" . $filename;
          $logger-&gt;error($message);
      }
  </code></pre>