title: LOCK PUT UNLOCK with cURL / WebDAV
body: <p>My idea is to <code>LOCK</code> a file on an apache/WebDAV server, <code>PUT</code> an updated version of it on the server and <code>UNLOCK</code> it afterwards. </p>
  
  <p>I just tried the following with cadaver: </p>
  
  <ol>
  <li>create a file <code>A.txt</code> with content <code>a file</code></li>
  <li><code>GET</code> file <code>A.txt</code> which yields <code>a file</code></li>
  <li>edit <code>A.txt</code> to be <code>updated file</code> and save it (in cadaver)</li>
  <li><code>GET</code> file <code>A.txt</code> which yields still yields <code>a file</code></li>
  <li>close edit (VIM) in cadaver</li>
  <li><code>GET</code> file <code>A.txt</code> which yields <code>updated file</code> </li>
  </ol>
  
  <p>I guess internally cadaver <code>LOCK</code>s the file, <code>GET</code>s it and changes it locally. Then it <code>PUT</code>s it and <code>UNLOCK</code>s it. </p>
  
  <p><strong>QUESTION</strong>: how can I do this with curl?</p>
  
  <p><strong>PROBLEM</strong>: When then connection is slow and I do a <code>PUT</code> for a file, that is not yet completely uploaded, I only get the yet uploaded part. I would like to get the old one as long as the new one isn't complete.</p>
  
  <p><strong>TRIED</strong>: I tried the following to LOCK the file by hand (i.e. with cURL):</p>
  
  <pre><code>curl -v -X LOCK --user "user:password" http://myServer/newFile
  </code></pre>
  
  <p>What I get is:</p>
  
  <pre><code>* About to connect() to myServer port 80 (#0)
  *   Trying xx.xx.xxx.xxx... connected
  * Connected to myServer (xx.xx.xxx.xxx) port 80 (#0)
  * Server auth using Basic with user 'user'
  &gt; LOCK /newFile HTTP/1.1
  &gt; Authorization: Basic xxxxxxxxxxxxxxxxx
  &gt; User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
  &gt; Host: myServer
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 400 Bad Request
  &lt; Date: Wed, 02 May 2012 15:20:55 GMT
  &lt; Server: Apache/2.2.3 (CentOS)
  &lt; Content-Length: 226
  &lt; Connection: close
  &lt; Content-Type: text/html; charset=iso-8859-1
  &lt; 
  &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;400 Bad Request&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Bad Request&lt;/h1&gt;
  &lt;p&gt;Your browser sent a request that this server could not understand.&lt;br /&gt;
  &lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  * Closing connection #0
  </code></pre>
  
  <p>Looking at the apache log file I find:</p>
  
  <pre><code>[Wed May 02 15:20:55 2012] [error] [client xx.xx.xxx.xxx] The lock refresh for /newFile failed because no lock tokens were specified in an "If:" header.  [400, #0]
  [Wed May 02 15:20:55 2012] [error] [client xx.xx.xxx.xxx] (20)Not a directory: No locktokens were specified in the "If:" header, so the refresh could not be performed.  [400, #103]
  </code></pre>
  
  <p>Thanks for any hint!!</p>
  
  <p><strong>UPDATE</strong>: I added my problem description.. Cheers!</p>