Shell Script for Upload/download files using cURL

hi

please help me out here,

i want to use curl command in shell script to test web pages,

what i have is an opening page, when i click on a button on opening page, the next page comes up and then i have to upload a file n then click another button to submit and then comes the output page, where i have to click that button to download the output.

Thanks in advance

I recently wrote a script to simulate some web transactions recently (not too different than yours), I had good luck following this tip from curl's website (hxxp://curl.haxx.se/docs/httpscripting.html):

If there are 3 clicks, then there are going to be 3 separate curl commands. You should be able to avoid the first "click", because you'll just be uploading the file in step 2, no need to browse to the first page once you figure out the URL of your POST.

I'm making up examples in as I don't know what your actual HTML form looks like. The trick is figuring out the form query variables (order matters!!) and converting that into your curl command-line arguments.

#/bin/sh
# 1.  Get page - probably not required
curl http://www.mysite.com/mypage.htm

# 2.  Upload file - most likely a multipart form.  the '@' means upload a local file
curl -F "upload_filename=@/full/path/to/local/file.txt" -F "myotherqueryvar=queryvalue" \
-L http://www.mysite.com/upload-page.htm > html_out.htm

# 3.  Parse HTML - you'll basically have to look at the return page
# and see if you can figure out a pattern that will grab the link.
mylink=`grep (insert pattern here that will get your link) html_out.htm`
curl ${mylink}

Not sure if you can just supply the actual website... might be easier to give you the exact commands.

-dufftime

1 Like