Example topics
/ Getting a remote folder's contents (VB example)
In This Topic
Getting a remote folder's contents (VB example)
In This Topic
This example demonstrates the 8 following steps for listing files with the GetFolderContents method:
Specify the FTP server's address
Specify the username to login
Specify the password for the username
Connect to the FTP server
Obtain the directory listing object
Disconnect from the FTP server
Process the listed items
Perform error handling
The following code assumes you have placed an XceedFtp control and a Listbox on a form and have called them 'XceedFtp1' and 'List1' respectively (the default names)
If Err.Number = 0 Then ' step (8) MsgBox "Successfully connected to server. Obtaining folder listing."
Dim xFolderItems As XceedFtpFolderItems ' step (5)
Set xFolderItems = XceedFtp1.GetFolderContents("",fcfCollection) ' step (5)
If Err.Number = 0 Then ' step (8) MsgBox "Successfully obtained folder listing. Disconnecting. "
Call XceedFtp1.Disconnect ' step (6)
Dim xItem As XceedFtpFolderItem ' step (7)
For Each xItem In xFolderItems ' step (7) Select Case xItem.ItemType Case fitFile List1.AddItem ("File: " & xItem.ItemName & _ " (" & CStr(xItem.FileSize)) & " bytes)"
Case fitFolder List1.AddItem ("Folder: " & xItem.ItemName) Case fitLink List1.AddItem ("Link: " & xItem.ItemName & ) " (" & CStr(xItem.FileSize)) & " bytes)" End Select Next xItem Else MsgBox "Error while obtaining folder listing. Description: '" & _ Err.Description & "'. Error code#" & Err.Number
Call XceedFtp1.Disconnect ' step (6) End If Else MsgBox "Error while connecting. Description: '" & Err.Description & _ "'. Error code#" & Err.Number End If