Multiple File Mask for WinSCP Session.EnumerateRemoteFiles

Advertisement

febesuvu
Joined:
Posts:
1
Location:
Winigan

Multiple File Mask for WinSCP Session.EnumerateRemoteFiles

I am rebuilding the FTP part of a performance monitor application, should be able to upload any file with extensions
.csv .xlsx .xls
and when i try to customize this mask it returns 0 files, but if i select only one of them it works fine.
string FileMask = "*.csv; *.xlsx; *.xls";
 
var sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = ConfigurationManager.AppSettings["FtpHost"],
    UserName = ConfigurationManager.AppSettings["FtpUsr"],
    Password = ConfigurationManager.AppSettings["FtpPwd"],
    SshHostKeyFingerprint = ConfigurationManager.AppSettings["SshHostKeyFingerprint"]
};
 
using (Session session = new Session())
{
    session.Open(sessionOptions);
 
    List<string> files =
        session.EnumerateRemoteFiles("/", FileMask, EnumerationOptions.AllDirectories)
        .Select(fileInfo => fileInfo.FullName)
        .ToList();
 
    Console.WriteLine($"Found {files.Count} files");
}
Last edited by febesuvu on 2021-05-04 05:57; edited 1 time in total

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,465
Location:
Prague, Czechia

Re: Multiple File Mask for WinSCP Session.EnumerateRemoteFiles

The Session.EnumerateRemoteFiles supports a single mask only. If you need to use multiple masks, you will have to enumerate all files and select those you want yourself in your code.

Reply with quote

Advertisement

You can post new topics in this forum