Call now to talk to an automation expert — (512) 345-2211

Script Library

Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.


http_post_file2.s

Download

Note: Make sure you really need to do a POST. If you are simply uploading a file it may be simpler to use the SENDFILE command (which uses the HTTP verb PUT instead of POST).

Note: This process is a little more complicated if you are using Robo-FTP v3.6. If you are using v3.6, see Sample Script #16.

As of v3.6.0 and later, Robo-FTP supports automating communication via HTTP and HTTPS.

One of the more complicated scenarios to automate is the process of communicating interactively with a web site and uploading data via a web form.

HTTP web forms come in 2 basic varieties:

application/x-www-form-urlencoded

This is the default type of form. It can be submitted using either an HTTP GET or an HTTP POST.

Submit via GET

This type is less common and is not the focus of this sample. Automating this type of form is very easy. You simply need to construct a url of the form:

 http://www.myurl.com/subdir/script.asp?field1=value1&field2=value2

This can be accomplished with a simple three-line Robo-FTP script:

 FTPLOGON "www.myurl.com" /servertype=HTTP
 FTPCD "subdir"
 RCVFILE "script.asp?field1=value1&field2=value2" /as "localfilename.html"

This type of form can only be used for submitting ASCII characters.

Submit via POST

This is the most common type of form submission and is also used to submit ASCII characters in field=value pairs as above. The only difference is instead of appending the form data to the url, the data is added to the body of the POST.

The sample script below demonstrates how to submit this type of form.

multipart/form-data

This type must be explicitly specified in the <form> tag's enctype attribute like this:

 <form action="http://www.myurl.com" method="post" enctype="multipart/form-data">

This type of form submits data via POST as described above, but can also include a file upload. This is the only type of form that can cover the entire ISO10646 character set.

Uploading a file via this type of form is defined in RFC 2388.

The sample script below demonstrates how to submit this type of form.

The fields, values, and URL used in the script below are examples and will need to be replaced with whatever fields, values, and URL the system you are trying to submit to requires.


  1  SET %field1 = "field1 value"
  2  SET %field2 = "field2 value"
  3  SET %filename = "C:\files\files.zip" 
  4  
  5  FTPLOGON "HTTP Site"
  6  PREPAREPOST /contenttype="multipart/form-data"
  7  ;; you may be able to use /contenttype="application/x-www-form-urlencoded" if you are not uploading a file
  8  postvalue "field1" %field1
  9  postvalue "field2" %field2
 10  postvalue "userfile" %filename /file /contenttype="application/zip"
 11  ;; Leave above line out if you are not posting a file
 12  HTTPPOST "/poster.asp" "" %postresult /outtype=string /intype=prepared 
 13  FTPLOGOFF

Browse complete list of scripts

Need help figuring out where to start?

Our sales staff is available to answer product questions and help you determine if Robo-FTP is a good match for your project.

Call Now: (512) 345-2211