SFTP file list

Demonstrates the power of GetList method and SftpItemCollection class.

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

C#

// select the desired directory
sftp.ChangeDirectory(path);

// retrieve and display the list of files and directories
SftpItemCollection list = sftp.GetList();
foreach (SftpItem item in list)
{
    Console.Write(item.LastWriteTime.Value.ToString("u"));
    Console.Write(item.Length.ToString().PadLeft(10, ' '));
    Console.Write(" {0}", item.Name);
    Console.WriteLine();
}

VB.NET

' select the desired directory
sftp.ChangeDirectory(path)

' retrieve and display the list of files and directories
Dim list As SftpItemCollection = sftp.GetList()
Dim item As SftpItem
For Each item In list
    Console.Write(item.LastWriteTime.Value.ToString("u"))
    Console.Write(item.Length.ToString().PadLeft(10, " "c))
    Console.Write(" {0}", item.Name)
    Console.WriteLine()
Next item

It is that simple!