If you are using .NET 3.5 or newer you can use LINQ
to sort this collection. Check following code:
using (Ftp ftp = new Ftp())
{
ftp.Connect("host");
ftp.Login("username", "password");
FtpList items = ftp.GetList();
IEnumerable<FtpItem> sortedItems =
items.OrderByDescending(n => n.Name);
foreach (FtpItem item in sortedItems)
{
Console.WriteLine("{0}", item.Name);
}
ftp.Disconnect();
}
If you cannot use LINQ
try this code:
using (Ftp ftp = new Ftp())
{
ftp.Connect("hostname");
ftp.Login("username", "password");
FtpList items = ftp.GetList();
items.Sort(new FtpItemComparer(FtpItemComparerType.Name));
foreach (FtpItem item in items)
{
Console.WriteLine("{0}", item.Name);
}
ftp.Disconnect();
}
The code for SFTP is almost the same. Just replace FtpList
with SftpList
, Ftp
with Sftp
and FtpItemComparer
with SftpItemComparer
.