使用 WinSCP .NET 程序集从 FTP 服务器下载除特定文件夹之外的所有文件
Download all files except a specific folder from FTP server using WinSCP .NET assembly
到目前为止,这是我用来获取文件夹内所有项目的代码,但在此文件夹内,有一个我不想包含在下载中的子文件夹,有没有办法不包括那个文件夹?
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
这是我用来下载所有文件的全部代码
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);
}
}
编辑:这是我在 FileMask
中尝试过的
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "/*.*|/.git";
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
使用TransferOptions.FileMask
即
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "*.* | .git/";
...
...
transferResult = session.GetFiles("/someremotefolder/*.*", @"D:\Download\", false, transferOptions);
注意:
- 竖线 |
分隔符结合了 include
和 exclude
掩码。
到目前为止,这是我用来获取文件夹内所有项目的代码,但在此文件夹内,有一个我不想包含在下载中的子文件夹,有没有办法不包括那个文件夹?
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
这是我用来下载所有文件的全部代码
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);
}
}
编辑:这是我在 FileMask
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "/*.*|/.git";
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/*.*", @"D:\Download\", false, transferOptions);
使用TransferOptions.FileMask
即
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "*.* | .git/";
...
...
transferResult = session.GetFiles("/someremotefolder/*.*", @"D:\Download\", false, transferOptions);
注意:
- 竖线 |
分隔符结合了 include
和 exclude
掩码。