Xceed FTP Library Documentation
Listing a remote folder's contents (C# example)
Example topics > Listing a remote folder's contents (C# example)
C# Copy Code

XceedFtpLib.XceedFtp ftp = new XceedFtpLib.XceedFtpClass();
ftp.License( @"your license key" );

// Specify the FTP server's address
ftp.ServerAddress = @"ftp.cdrom.com";

// Specify the username and password to login
ftp.UserName = "anonymous";
ftp.Password = "guest";

try
{
   // Connect to the FTP server
   ftp.Connect();

   // Subscribe to the ListingFolderItem event in order
   // to display the contents of remote folder.
   ftp.ListingFolderItem += new XceedFtpLib.DXceedFtpEvents_ListingFolderItemEventHandler( this.ftp_ListingFolderItem );
       
   // List the root folder's content
   ftp.ListFolderContents( "" );

   // Disconnect from the FTP server
   ftp.Disconnect();
}
catch( System.Runtime.InteropServices.COMException except )
{
   MessageBox.Show( except.ToString() );
}

// In this event we will right the name of each item into a listbox located on our form.
private void ftp_ListingFolderItem( string name, DateTime date, int fileSize, XceedFtpLib.EXFFolderItemType itemType, string userData )
{
   listBox1.Items.Add( name );
}