FTP file list (.NET Compact Framework)

Demonstrates the power of GetList method and FtpList class.

A utility that connects to a given FTP server and displays file list for a given directory (both VB.NET and C#).

The format of the file list (FTP LIST command) differs from server to server. But with Rebex FTP for .NET Compact Framework, retrieving and using list of files in directory is extremely easy - GetList method does all the hard work and parses all common list formats automatically! Following code snippet displays the list of files in the remote directory:

C#

// select the desired directory
ftp.ChangeDirectory("path");

// retrieve the list of files and directories
FtpItemCollection list = ftp.GetList();

// display retrieved items
listView.BeginUpdate();

foreach (FtpItem item in list)
{
    ListViewItem listViewItem = new ListViewItem(item.Name);
    listViewItem.SubItems.Add(item.Length.ToString());
    listView.Items.Add(listViewItem);
}

listView.EndUpdate();

VB.NET

' select the desired directory
ftp.ChangeDirectory("path")

' retrieve the list of files and directories
Dim list As FtpItemCollection = ftp.GetList()

' display retrieved items
listView.BeginUpdate()

Dim item As FtpItem
For Each item In list
    Dim listViewItem As ListViewItem = New ListViewItem(item.Name)
    listViewItem.SubItems.Add(item.Length.ToString())
    listView.Items.Add(listViewItem)
Next item

listView.EndUpdate()

It is that simple even in .NET Compact Framework!