【问题标题】:fluentftp upload directory skip subfoldersfluentftp上传目录跳过子文件夹
【发布时间】:2020-06-18 18:04:50
【问题描述】:

我使用 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);

【问题讨论】:

    标签: c# fluentftp


    【解决方案1】:

    您需要添加 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&lt;FtpResult&gt;,显示哪些文件已成功上传以及哪些文件夹/文件被规则跳过。

    【讨论】:

      猜你喜欢
      • 2020-05-19
      • 2019-01-02
      • 1970-01-01
      • 2018-01-12
      • 2016-11-27
      • 2012-08-22
      • 2013-08-20
      • 1970-01-01
      • 2011-10-28
      相关资源
      最近更新 更多