fluentftp上传目录跳过子文件夹

fluentftp upload directory skip subfolders

我使用 fluentftp 库将文件夹上传到 ftp。 我怎样才能跳过目录的子文件夹。

              // upload only PDF files
            var rules = new List<FtpRule>{
               new FtpFileExtensionRule(true, new List<string>{ "pdf" }),
               new FtpFolderNameRule(false, FtpFolderNameRule.CommonBlacklistedFolders)
               // only allow PDF files
            };
            ftp.UploadDirectory(ServiceAbrechnungPath, @"/Abrechnungen",
                FtpFolderSyncMode.Mirror, FtpRemoteExists.Skip, FtpVerify.None, rules);

您需要添加 FtpFolderNameRule 以排除子文件夹。

使用您的代码,它看起来像这样;

using System.Linq

//Get a list of subfolders in the root folder without their path name.
//This should be just the folders in the root folder i.e. you don't need a recursive list of folders within these folders    
var subfolders = Directory.GetDirectories(ServiceAbrechnungPath).Select(subDirectory => subDirectory.Remove(0, ServiceAbrechnungPath.Length)).ToList();

// upload only PDF files in the root of ServiceAbrechnungPath
var rules = new List<FtpRule>{
    new FtpFileExtensionRule(true, new List<string>{ "pdf" }), // only allow PDF files
    new FtpFolderNameRule(false, subfolders)  // exclude subfolders    
};

var uploadResult = ftp.UploadDirectory(ServiceAbrechnungPath, @"/Abrechnungen", FtpFolderSyncMode.Mirror, FtpRemoteExists.Skip,FtpVerify.None, rules);

uploadResult 变量将包含一个 List<FtpResult> 显示哪些文件已成功上传,哪些 folders/files 被规则跳过。