Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Uploading a file using FTP


In a previous recipe, we have seen how to download a file using XMLHttp. Here we will see how to upload a file to a web server using the FTP protocol.

Getting ready

From the File menu, navigate to New | Function Library or use the Alt + Shift + N shortcut. Name the new function library FTP.vbs. Make sure the library is associated to the test. In order to use the code given in this recipe, you must have an FTP user account on a server. To understand this recipe, you should be familiar with FTP protocol and the command line.

How to do it...

In the function library, we will put the following code.

  1. First we will define the following constants for better readability and reusability:

    const C_FSO="Scripting.FileSystemObject"
    const C_SHELL="WScript.Shell"
    const C_ASCII="ascii", C_BIN="binary"
    const C_FTP_CMD="%comspec% /c FTP -n -s:"
    const C_SYNC_TIME=5000
    const C_TEMP="%TEMP%"
    const C_OPENASDEFAULT=-2
    const C_FAIL_IFNOT_EXIST=0
    const C_FORREADING=1
    const C_FORWRITING=2
    const...