title: How to get file from POST data in Bash CGI script?
body: <p>I am trying to post a file using cURL and receive it on the other side via a CGI Bash script and store it with the same name. After upload is completed, <code>diff</code> between the original file and reconstructed one should return zero.   </p>
  
  <p>The way cURL sends data:</p>
  
  <pre><code>curl --request POST --data-binary "@dummy.dat" 127.0.0.1/cgi-bin/upload-rpm
  </code></pre>
  
  <p>Receiver script:</p>
  
  <pre><code>#!/bin/bash
  
  echo "Content-type: text/html"
  echo ""
  
  echo '&lt;html&gt;'
  echo '&lt;head&gt;'
  echo '&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;'
  echo '&lt;title&gt;Foo&lt;/title&gt;'
  echo '&lt;/head&gt;'
  echo '&lt;body&gt;'
  
  echo "&lt;p&gt;Start&lt;/p&gt;"
  
  if [ "$REQUEST_METHOD" = "POST" ]; then
      echo "&lt;p&gt;Post Method&lt;/p&gt;"
      if [ "$CONTENT_LENGTH" -gt 0 ]; then
          echo "&lt;p&gt;Size=$CONTENT_LENGTH&lt;/p&gt;"
          while read -n 1 byte -t 3; do echo -n -e "$byte" &gt;&gt; ./foo.dat ; done
      fi
  fi
  echo '&lt;/body&gt;'
  echo '&lt;/html&gt;'
  
  exit 0
  </code></pre>
  
  <p>But it's not working. File is not created on the server side. And how can I get the file name?</p>