Batch file that checks FTP folder if any file matching a mask exist

前端 未结 1 539
野趣味
野趣味 2021-01-17 04:10

I need to create a batch file that goes to a protected FTP site, checks if a file type (*.txt) exists, and if it does, proceed to the next step, if not, return

1条回答
  •  迷失自我
    2021-01-17 04:50

    It's not a trivial task, particularly if you need to check for a file matching a mask (not for a specific file).

    You can use 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
    

    The above code is from the WinSCP article on Checking file existence.

    (I'm the author of WinSCP)

    0 讨论(0)
提交回复
热议问题