Xceed FTP Library Documentation
Getting a remote folder's contents (VB example)
Example topics > Getting a remote folder's contents (VB example)

This example demonstrates the 8 following steps for listing files with the GetFolderContents method:

  1. Specify the FTP server's address
  2. Specify the username to login
  3. Specify the password for the username
  4. Connect to the FTP server
  5. Obtain the directory listing object
  6. Disconnect from the FTP server
  7. Process the listed items
  8. 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)

Visual Basic Copy Code

Call XceedFtp1.License( "your license key" ) 

XceedFtp1.ServerAddress = "ftp.cdrom.com" ' step (1)
XceedFtp1.UserName = "anonymous" ' step (2)
XceedFtp1.Password = "guest" ' step (3) 

On Error Resume Next ' step (8) 

Call XceedFtp1.Connect ' step (4) 

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