Just retrieve the list of files, download any new ones, and repeat. There's no better way, unless the uploading component can provide some metadata.
var client = new SftpClient(host, user, password);
client.Connect();
var prevFiles = new List<string>();
while (true)
{
var files =
client.ListDirectory(remotePath)
.Where(_ => _.IsRegularFile)
.Select(_ => _.Name)
.ToList();
var newFiles = files.Except(prevFiles);
if (!newFiles.Any())
{
Console.WriteLine("No new files");
}
else
{
Console.WriteLine($"Found {newFiles.Count()} new files");
foreach (string file in newFiles)
{
Console.WriteLine($"Downloading {file}...");
using (var fileStream = File.Create(Path.Combine(localPath, file)))
{
client.DownloadFile(remotePath + "/" + file, fileStream);
}
}
}
prevFiles = files;
Console.WriteLine("Sleeping...");
Thread.Sleep(10000);
}
If you keep the local files, you might modify the code to synchronize against the local files instead of keeping the file list in memory. Though afaik, SSH.NET does not support remote-to-local synchronization.
So either you would have to implement simple one-way synchronization yourself (what won't be a big change from the above code), or you would have to use another library. For that, see Continuously sync changes from web server.