Using FTP OLE Automation

image\rwnprg32.gif Sample Code: Receive Files

 

The following sample code logs into an FTP server and retrieves files.

' ReceiveFile Sample

' The following sample code logs into an FTP server and

' retrieves files.

'

Sub Main

 ' Allocate space for an Automation Object

 ' Using early binding syntax, which is recommended.

 Dim Ftp As ReflectionFTP3

 

 ' This commented line shows late binding syntax. (Not recommended.)

 'Dim Ftp As Object

 

 ' Create the Reflection FTP Object

 '

 Set Ftp = CreateObject("Reflection.FTP")

 ' Connect to the Ftp Site and Login

 ' Since the username and password aren't specified

 ' Reflection FTP will prompt for them.

 '

 Ftp.Open "ftp.wrq.com"

 ' Transfer all ".txt" (text) files from the current directory

 ' on the server to the current local directory.

 ' Transfer the files as ASCII and prompt the user if the

 ' file already exists.

 '

 Ftp.ReceiveFile "", "*.txt", rcAscii, rcAskUser

 ' Change to the 'bussys' directory on the server

 '

 Ftp.SetCurrentDirectory "bussys"

 ' Transfer a file named 'readme.txt' as binary and skip

 ' the transfer if the file already exists.

 '

 Ftp.ReceiveFile "", "readme.txt", rcBinary, rcSkip

 ' Log out of FTP Site and disconnect

 '

 Ftp.Close

 ' We're all done with the object - free up the resource

 '

 Set Ftp = Nothing

End Sub