[CentOS] Bash cgi upload form

John Doe jdmls at yahoo.com
Mon Jan 5 12:30:58 UTC 2009


> From: Sean Carolan <scarolan at gmail.com>

> 
> Anyone have a function or script for uploading files from a web
> browser with a bash script?  I know this is possible to do with Perl,
> I'm wondering if the same is possible using only bash.

I use curl.
It can be a bit tricky if you use POSTDATA...
Here's the function I use:

# upload_file <URL> <POSTDATA> <FILE>
function upload_file() {
  URL="$1"
  DATA="$2"
  FILE="$3"
  PARAMS="-F \"file=@$FILE\""
  IFS="&"
  for PARAM in $DATA
    do
      PARAMS="$PARAMS -F \"$PARAM\""
    done
  IFS=" "
  eval `echo curl $PARAMS $URL 2>/dev/null`
  if [ $? -ne 0 ]; then echo "curl error $?"; fi
}

JD


      



More information about the CentOS mailing list