On Mon, Jan 05, 2009 at 04:30:58AM -0800, John Doe wrote: > > 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 Hi John, Just curious here, from Sean's request info, this script would run on the web server the user was connected to. How will this curl command be able to "pull" the file from the user's system up on to the server? I know that curl can be used to send data to or from a server, but it usually seems to be running on the user's system (eg the browser side of the relationship). In this case wouldn't it be running on the server? I seem to be missing part of the flow here. Curl is my favorite CLI web tool. If it can do this I want to understand it. As I understand it, The user's machine would need to be running an http (or ftp) service in order to fulfill this curl request originating from the server. I keep rechecking the curl man page and I'm still missing it. I've probably overlooked something basic. :-) JK Jeff Kinz