Sample: FTP File List
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, 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 and display the list of files and directories
FtpList list = ftp.GetList();
foreach (FtpItem item in list)
{
Console.Write(item.Modified.ToString("u"));
Console.Write(item.Size.ToString().PadLeft(10, ' '));
Console.Write(" {0}", item.Name);
Console.WriteLine();
}
VB.NET
' select the desired directory
ftp.ChangeDirectory("path")
' retrieve and display the list of files and directories
Dim list As FtpList = ftp.GetList()
Dim item As FtpItem
For Each item In list
Console.Write(item.Modified.ToString("u"))
Console.Write(item.Size.ToString().PadLeft(10, ""c))
Console.Write(" {0}", item.Name)
Console.WriteLine()
Next item
It is that simple!
See also: