You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

lftp使用mirror命令排除指定子目录不生效该如何解决?

lftp mirror子目录排除规则失效修复方案

  • 规则匹配逻辑修正
    lftp的mirror命令--exclude参数使用正则匹配,匹配范围为文件/目录相对于同步源根目录$ftproot的完整路径,原规则失效主要是两个匹配逻辑问题:
    • 路径末尾的/仅能匹配空目录,非空目录无法被命中
    • 未锚定路径开头,可能出现匹配偏移无法命中目标路径
      三个子目录排除规则修改为如下写法即可:
    --exclude ^images/product_images/popup_images
    --exclude ^images/product_images/info_images
    --exclude ^images/product_images/thumbnail_images
    
  • 引号嵌套解析问题修复
    原命令中-e参数外层使用双引号,内层--exclude-glob的单引号会被shell提前解析,导致规则未正确传递给lftp,将两个glob规则的单引号替换为转义双引号:
    --exclude-glob \"*.log*\"
    --exclude-glob \"*.zip*\"
    
  • 最终可用命令参考
    lftp -u $ftpuser,$ftppass -p 21 $ftpserver -e "set ftp:ssl-allow on; set ssl:check-hostname no; mirror -P $ftpconnections $ftproot $backupfolder/$date-$user/ --exclude ^images/product_images/popup_images --exclude ^images/product_images/info_images --exclude ^images/product_images/thumbnail_images --exclude-glob \"*.log*\" --exclude-glob \"*.zip*\"; quit"
    
  • 规则验证方法
    修改完成后可在mirror参数后添加--dry-run参数测试同步列表,不会实际下载文件,可快速验证排除规则是否生效:
    mirror --dry-run -P $ftpconnections ...其余参数保持不变
    

内容的提问来源于stack exchange,提问作者Karsten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 18:57:03