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 default FTP site, uploads a file, retrieves and displays the value of an internal Robo-FTP variable, and then logs off the site. 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.
' 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" ResultCode = FTPReq.RoboSendCommand(cmdString, 600)
' upload a file ' ---------------------- cmdString = "SENDFILE 'ReadMe.txt' " ResultCode = FTPReq.RoboSendCommand(cmdString, 600) '600 = 60 second timeout
' 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
See also: COM/OLE Operational Overview, COM Programming Reference |