Search code examples
batch-fileftpdirectorydosexists

cmd dos check if a remote FTP folder exists


I want to know how to check if FTP directory exists, using a batch dos or command.

PS: Obviously I do not need the root of the server, but a subdirectory, otherwise I would have been enough ping it.

thanks


Solution

  • You could use an ftp script that tries to change to the directory and then parse the output looking for the 550 error code that says you cannot. Something like the following works for me...

    @Echo off
    
    echo open ftp.mysite.com>test.ftp
    echo ftpusername>>test.ftp
    echo ftppassword>>test.ftp
    echo cd %1>>test.ftp
    echo quit>>test.ftp
    
    for /f %%i in ('ftp -s:test.ftp') do if {%%i} EQU {550} echo Does not exist