To search for a file at FTP

后端 未结 1 1531
独厮守ぢ
独厮守ぢ 2021-01-25 04:47

I want to find if a file exists at FTP using if-exist filename -else statement using FTP batch script which is as follows:

ftp.txt open ftp.mysite.com
ftp.txt us         


        
相关标签:
1条回答
  • 2021-01-25 05:20

    Don't do the logic in the FTP script.

    Call the ftp.txt script from a batch file. Within your ftp.txt script, just do a GET on your file. If the file is there, it'll be downloaded to the local directory. Otherwise, it won't. After calling the FTP script, check the file's existence in your local directory using standard DOS batch commands, i.e.:

    @echo off
    
    :FETCHFILE
    ftp -s:ftp.txt
    IF EXIST filetocheckfor.txt (
       REM the file was there, so do something
    ) ELSE
       echo Trying again...
       REM ping "sleep" would go here
       GOTO FETCHFILE
    )
    

    If you want to build a delay into your retries, perform a "sleep" by pinging a bogus IP address, as described in this post: http://www.dullsharpness.com/2010/06/14/elapsed-timer-using-pure-ms-dos/

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