代码之家  ›  专栏  ›  技术社区  ›  John Michael

检查ftp文件是否存在并分析退出代码

  •  0
  • John Michael  · 技术社区  · 7 年前

    我需要通过wget检查文件是否存在,并测试退出代码

    现在,我运行这个:

    wget -q --spider --ftp-user='ftpuser'--ftp-password='ftpassword' ftp://192.168.1.63/fileexists.txt
    echo $? #0
    

    及其 return code is 0

    但如果文件不存在

    wget -q --spider --ftp-user='ftpuser'--ftp-password='ftpassword' ftp://192.168.1.63/filenotexist.txt
    echo $? #0
    

    它的 return code is equal 0, 即使没有

    所以我试过了 不带--十字轴选项 我得到了 8作为退出代码 ,表示该文件不存在

    但是,如果有一个,wget实际上会下载它。 问题是如果我有 大文件 要“检查”。。

    有什么想法吗?

    谢谢

    1 回复  |  直到 7 年前
        1
  •  3
  •   Viktor Khilin    7 年前

    使用curl怎么样?

     curl -I --silent ftp://username:passwd@192.168.1.63/filenotexist.txt >/dev/null
    

    $? 如果文件存在,则为0, $? 如果文件不存在,则不是0。