Example

This procedure configures the FTP protocol, starts the FTP file server, transfers files in both directions, and then disconnects from the server.

After transferring all *.txt files in the current folder to the host, the procedure transfers a specific file, "Sample.jpg," to the local computer. If this is not one of the files on the host, an error is returned. The error handler ensures that the FTP server is disconnected.

Example

Sub FTPExample()

With Session

On Error GoTo Handler

 

'Setup FTP protocol to a UNIX host

.TransferDefaultProtocol = rcFTP

.TransferPreset = "To UNIX Using Reflection FTP"

 

'Replace the line above with this one for connections

'to a VMS host

'.TransferPreset = "To OpenVMS using Reflection FTP"

 

'Connect to the FTP server. This example specifices a

'username, but no password.

.FTPStartServer "MyUsername"

 

'Send all .txt files in the current folder to the host

'using ASCII format. Overwrite any existing files.

.FTPSendFile "C:\Test\*.txt", "", rcASCII, rcDelete

 

'Receive a specific file from the host. Ask the user

'what to do if the file already exists on the PC.

'Note: An error is returned if Sample.jpg is not on

'the host and the procedure goes to Handler:.

.FTPReceiveFile "", "Sample.jpg", rcBinary, rcAskUser

 

'Disconnect from the file server

.FTPStopServer

 

Exit Sub

 

'This error handler is not very helpful, but at least it

'ensures that the FTP server is disconnected if an error occurs.

Handler:

MsgBox "An FTP file transfer error occurred."

.FTPStopServer

Exit Sub

End With

End Sub