Reputation: 320
So far this is the code I'm using to get the All items inside of a folder but inside of this folder, has a sub folder i don't want to include in downloading, is there a way to not include that folder ?
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
This is the whole code I'm using to download all files
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "sample",
UserName = "sample",
Password = "sample",
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Your code
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
listBox1.Items.Add("Files Downloaded : "+ transfer.FileName);
}
}
EDIT : This is what I tried in FileMask
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "/*.*|/.git";
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
Upvotes: 2
Views: 1261
Reputation: 1144
Use TransferOptions.FileMask
i.e.
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "*.* | .git/";
...
...
transferResult = session.GetFiles("/someremotefolder/*.*", @"D:\Download\", false, transferOptions);
NOTE:
- The pipe |
separator combines include
and exclude
masks.
More details: https://winscp.net/eng/docs/file_mask#include_exclude
Upvotes: 4