I'm trying to get the files from the SFTP server. The goal is, to get files newer than 24 hours.
This mask works. The count returns 9018.
var filesCount1 =
session.EnumerateRemoteFiles(
serverPath, "*.xml", WinSCP.EnumerationOptions.None).Count();
This mask does not work. The count returns 0.
var filesCount2 =
session.EnumerateRemoteFiles(
serverPath, "*.xml>24HS", WinSCP.EnumerationOptions.None).Count();
How can I fix it? I want to get file one by one, because I need to do some validation before the download.
As documented, Session.EnumerateRemoteFiles
supports simple Windows wildcards only:
https://winscp.net/eng/docs/library_session_enumerateremotefiles#parameters
But you can simply filter the enumeration that the method returns:
DateTime limit = DateTime.Now.AddDays(-1);
var filesCount1 =
session.EnumerateRemoteFiles(
serverPath, "*.xml", WinSCP.EnumerationOptions.None)
.Where(file => file.LastWriteTime > limit)
.Count();
Note that this counts "files newer than 24 hours", as you asked for. What is not what file mask >24HS
means. So I'm not sure what exactly are you after.