Skip to content

FTP Directory Listing Example

Andrew Lambert edited this page Sep 26, 2023 · 7 revisions

Remarks

libcURL can be used to enumerate a remote directory over FTP. To do so, use the FTPWildCard class and handle the QueueFile event. By Returning True from this event you can skip the download operation while still getting the remote filename, permissions, and directory/file status. Refer to the FTP download example for a demonstration of wildcard downloading.

Example

This example is a console application that prints the name of every file and directory in a remote FTP directory:

Class App
Inherits ConsoleApplication
     Event Function Run(args() as String) As Integer
        Dim w As New libcURL.FTPWildCard
        AddHandler w.QueueFile, WeakAddressOf QueueFileHandler
        Dim c As New cURLClient(w)
        c.Username = "username"
        c.Password = "seekrit"
        If Not c.Get("ftp://ftp.example.com/public/*") Then ' use a pattern in the URL
           Raise New libcURL.cURLException(w)
        End If
     End Function

     Private Function QueueFileHandler(Sender As libcURL.FTPWildCard, RemoteName As String, ByRef LocalFile As FolderItem, Type As Integer, UnixPerms As Permissions) As Boolean
        Print(RemoteName)
        Return True ' skip the download
     End Function
End Class
Clone this wiki locally