Example topics
/ Listing a remote folder's contents (VB example)
In This Topic
Listing a remote folder's contents (VB example)
In This Topic
This example demonstrates the 8 following steps for listing files with the ListFolderContents method:
Specify the FTP server's address
Specify the username to login
Specify the password for the username
Connect to the FTP server
Begin the listing process
Process each item being listed
Disconnect from the FTP server
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).
The first section of code below demonstrates all steps except step (6). Step (6), the handler for the ListingFolderItem event, is found right after.
If Err.Number = 0 Then ' step (8) MsgBox "Successfully connected to FTP server. Starting to list the contents of the current folder."
Call XceedFtp1.ListFolderContents("") ' step (5)
If Err.Number <> 0 Then ' step (8) MsgBox "Error while listing remote folder contents. Description: '" & Err.Description & "'. Error code#" & Err.Number End If
Call XceedFtp1.Disconnect ' step (7) Else MsgBox "Error while connecting. Description: '" & Err.Description & "'. Error code#" & Err.Number End If
' Step (6): The following code which adds the name and size of each ' item being listed into a listbox on your form) must go into the error ' handler for the ListingFolderItem event. Note: Do not copy and paste the ' event declaration from the code below. Have the header automatically ' generated by VB. You can copy the code between the header and the ' 'End Sub' though.
Private Sub XceedFtp1_ListingFolderItem(ByVal sName As String, ByVal dtDate As Date, ByVal lFileSize As Long, ByVal eItemType As XceedFtpLibCtl.EXFFolderItemType, ByVal sUserData As String) Select Case eItemType Case fitFile List1.AddItem ("File: " & sName & " (" & CStr(lFileSize)) & " bytes)" Case fitFolder List1.AddItem ("Folder: " & sName) Case fitLink List1.AddItem ("Link: " & sName & " (" & CStr(lFileSize)) & " bytes)" End Select End Sub