Hello,
this is example implementation of how something like this could be done. You can set timeouts in the loop to poll periodically and not all the time.
using var client = new Sftp();
client.Connect("test.rebex.net");
client.Login("demo", "password");
var files = new List<RemoteFile>()
{
new RemoteFile("/pub/example/readme.txt", client),
new RemoteFile("/pub/example/KeyGenerator.png", client),
new RemoteFile("/pub/example/ResumableTransfer.png", client)
};
TimeSpan delay = TimeSpan.FromSeconds(5); // set a safe value for you
while (files.Count > 0)
{
Thread.Sleep(delay); // wait a while
files = TryDownload(files, @"c:\data", client);
}
List<RemoteFile> TryDownload(List<RemoteFile> files, string targetFolder, Sftp client)
{
List<RemoteFile> updatedFiles = new List<RemoteFile>();
foreach (var file in files)
{
var size = client.GetFileLength(file.Path);
if (size == file.Size)
{
client.Download(file.Path, targetFolder);
}
else
{
file.Size = size;
updatedFiles.Add(file);
}
}
return updatedFiles;
}
class RemoteFile
{
public string Path;
public long Size;
public RemoteFile(string path, Sftp client)
{
Path = path;
Size = client.GetFileLength(path);
}
}