c# - fluentftp上传目录跳过子文件夹
问题描述
我使用 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>
显示哪些文件已成功上传以及哪些文件夹/文件被规则跳过。
推荐阅读
- php - 使用 php 以 html 格式将答案发送到电子邮件
- android - 在 Travis CI 中构建 apk 因“仪器失败”而失败
- javascript - 迭代嵌套数组,es6方式,我已经使用foreach完成了
- json - jq:从一个对象中提取特定键到另一个对象
- css - 如何在Vue中创建一个具有50%背景颜色的组件
- c - 从文件中读取输入的矩阵运算
- android - 如何从linkify textview获取url
- ios - UITableViewCell 高度根据 UIImageview 的纵横比展开
- javascript - 我怎样才能逃脱'。猫鼬更新操作中字段名称中的字符?
- mysql - c# 和 MySql - 服务器会停止运行多个(数千个)查询吗?