Get file from POST data int bash cgi script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Get file from POST data int bash cgi script



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, diff between the original file and reconstructed one should return zero.


curl


diff



The way curl sends data:


curl --request POST --data-binary "@dummy.dat" 127.0.0.1/cgi-bin/upload-rpm



Receiver script:


#!/bin/bash

echo "Content-type: text/html"
echo ""

echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Foo</title>'
echo '</head>'
echo '<body>'

echo "<p>Start</p>"

if [ "$REQUEST_METHOD" = "POST" ]; then
echo "<p>Post Method</p>"
if [ "$CONTENT_LENGTH" -gt 0 ]; then
echo "<p>Size=$CONTENT_LENGTH</p>"
while read -n 1 byte -t 3; do echo -n -e "$byte" >> ./foo.dat ; done
fi
fi
echo '</body>'
echo '</html>'

exit 0



But it's not working. File is not created on the server side. And how can I get the file name?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard