【问题标题】:Batch file that checks FTP folder if any file matching a mask exist如果存在任何匹配掩码的文件,则检查 FTP 文件夹的批处理文件
【发布时间】:2015-03-24 20:38:33
【问题描述】:

我需要创建一个批处理文件,它会转到受保护的 FTP 站点,检查文件类型 (*.txt) 是否存在,如果存在,则继续下一步,如果不存在,则返回 0 并结束工作。

我进行了广泛的搜索,但找不到任何解决方案。

【问题讨论】:

    标签: batch-file if-statement ftp


    【解决方案1】:

    这不是一项简单的任务,特别是如果您需要检查与掩码匹配的文件(而不是特定文件)。

    你可以使用WinSCP scripting:

    @echo off
    
    set REMOTE_PATH=/home/user/*.txt
    winscp.com /command ^
        "open ftp://user:password@host/" ^
        "option failonnomatch on" ^
        "ls %REMOTE_PATH%" ^
        "exit"
    
    if %ERRORLEVEL% neq 0 goto error
    
    echo File(s) matching %REMOTE_PATH% exist
    rem Do something
    exit 0
    
    :error
    echo Error or no file matching %REMOTE_PATH% exists
    exit 1
    

    以上代码来自Checking file existence上的WinSCP文章。

    (我是 WinSCP 的作者)

    【讨论】:

    • 我将上面的批处理运行为:"@echo off set REMOTE_PATH=/Staging/nononsense-tasks/OrdersOut/nn_OrdersOut_*.txt winscp.com /command ^"option batch abort"^"open @ 987654323@" ^ "option failonnomatch on" ^ "ls %REMOTE_PATH%" ^ "exit" if %ERRORLEVEL% neq 0 goto error echo 匹配 %REMOTE_PATH% 的文件存在 exit 0 :error echo 错误或没有文件匹配 %REMOTE_PATH % 存在 exit 1" 和我的用户名、密码和主机,当有文件时,它返回不存在文件。有什么建议吗?
    • 您似乎在使用 TLS 隐式加密。为此,open 命令需要看起来像:open ftps://username:password@host/ -implicit
    猜你喜欢
    • 2016-09-10
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多