/// <summary>
/// List a remote directory in the console.
/// </summary>
private void listFiles()
{
string host = @"yourSftpServer.com";
string username = "root";
string password = @"p4ssw0rd";
string remoteDirectory = "/some/example/directory";
using (SftpClient sftp = new SftpClient(host, username, password))
{
try
{
sftp.Connect();
var files = sftp.ListDirectory(remoteDirectory);
foreach (var file in files)
{
Console.WriteLine(file.Name);
}
sftp.Disconnect();
}
catch (Exception e)
{
Console.WriteLine("An exception has been caught " + e.ToString());
}
}
}