使用代码
you have found to download the one latest file
只需更换
FirstOrDefault
具有
Take
并迭代集合以下载所有选定的文件。
我也在使用
EnumerateRemoteFiles
而不是
ListDirectory
,因为它可以根据自己的文件屏蔽来过滤文件。
const string remotePath = "/remote/path";
const string localPath = "C:\local\path";
IEnumerable<RemoteFileInfo> files =
session.EnumerateRemoteFiles(remotePath, "*.csv", EnumerationOptions.None)
.Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.Take(10);
string destPath = Path.Combine(localPath, "*");
foreach (RemoteFileInfo file in files)
{
Console.WriteLine("Downloading {0}...", file.Name);
session.GetFiles(RemotePath.EscapeFileMask(file.FullName), destPath).Check();
}