Sample VBScript Program

Top  Previous  Next

 

The Robo-FTP COM object may be used in MS Excel macros, MS Access databases, and VBScript (VBS) programs. The following is an example VB Script that loads Robo-FTP, logs on to the an FTP site, changed directory, downloads a file, retrieves and displays the value of an internal Robo-FTP variable, and then logs off the site and closes Robo-FTP.

 

' Instantiate a Robo-FTP object

Set FTPReq = Createobject("RoboFTPAutomation.Automate")

 

If err.number <> 0 then

  msgbox "Failed to create COM object!"

  Wscript.quit 1

End If

 

' Set session properties and open session

ResultCode = FTPReq.RoboStartSession("", True, False, "")

 

If ResultCode <> -1 then

  msgbox "RoboStartSession Failed!" & vbCrLf & "Return value: " & ResultCode

  FTPReq.RoboEndSession

  Wscript.quit 2

End If

 

' log on to default site

cmdString = "FTPLOGON 'www.robo-ftp.com' /user=anonymous"

ResultCode = FTPReq.RoboSendCommand(cmdString, 600) '600 = 60 second timeout

 

' change remote working folder

cmdString = "FTPCD '/outgoing'"

ResultCode = FTPReq.RoboSendCommand(cmdString, 600)

 

' download a file

cmdString = "RCVFILE 'rfc959.txt' "

ResultCode = FTPReq.RoboSendCommand(cmdString, 600)

 

' get the last error

msgbox "Value of %lasterror = " & FTPReq.RoboGetVBSVariable("%lasterror")

 

' log off the site

cmdString = "FTPLOGOFF"

ResultCode = FTPReq.RoboSendCommand(cmdString, 600)

 

' end Robo-FTP session and exit

FTPReq.RoboEndSession

msgbox "Done"

Wscript.Quit 0

 

If you are using a 64-bit version of Windows be sure to run this file using the 32-bit version of cscript.exe located in the \Windows\SysWOW64 folder, otherwise you'll get an error creating the Automate object. If the sample above was saved on the desktop in a file named test.vbs then the command line on a 64-bit version of windows might look like this:

 

c:\windows\SysWOW64\cscript.exe c:\users\administrator\desktop\test.vbs

 

 

See also: COM/OLE Operational Overview, COM Programming Reference