FTP COM Object sample script

The following is a sample VBScript using the Rocket FTP Com Object. This script logs onto an FTP server and reports back the number files and directories found. To make it work, you have to replace the IP address and the username and password with your credentials.

Sub Main
  Const ftpASCII = 0  'support FTP_ASCII
  Const ftpBinary = 1 'support FTP_IMAGE 
  Const ftpSmart = 3  'support FTP_IMAGE 
  Const ftpTenex = 4 
  Const ftpAskUser = 0 
  Const ftpOverwrite = 1 
  Const ftpAppend = 2 
  Const ftpCancel = 4 
  Const ftpUpdate = 7 
  Const ftpSkip = 8 
  Const ftpUnique = 12

    Set Ftp = CreateObject( "RocketFTP.FtpSession" )

      If (Ftp Is Nothing) Then

        MsgBox "Unable to create Rocket FTP Com Object"

          Else

            MsgBox "You have successfully connected to the Rocket FTP Com Object, click OK to continue"
      
      End If

With Ftp

.Open "127.0.0.1", "username", "password"  'Change to your FTP Server's address and login credentials
 
  If (.LastError > 0) Then
    
    MsgBox "Err #: " & Ftp.LastError & vbCr & Ftp.LastErrorString
      
      Exit Sub
 
  End If

' .SetCurrentDirectory "\Home"  'This is used to set the desired directory if other than default
.OpenDirectoryListing "."

  FileCount = 0 
  DirCount = 0

FileInfoStr = "Directory Contains:" & vbCr

Do While .GetNextFileDetails

  If .FileIsDirectory = False Then

    DirCount = DirCount + 1

      Else

    FileCount = FileCount + 1

  End If

Loop

  FileInfoStr = FileInfoStr & "Total Files: " & FileCount & vbCr
  FileInfoStr = FileInfoStr & "Total Directorys: " & DirCount & vbCr

    MsgBox FileInfoStr

      '.ReceiveFile "pc.txt", "host.txt", ftpASCII ''This is provided to show the syntax to receive a file 
      '.SendFile "pc.txt", "host.txt", ftpASCII     'This is provided to show the syntax to send a file

    .Close

  End With

End Sub

Main