How can i perform a file check at ftp prompt

September 20, 2012 at 07:09:28
Specs: Windows 7
I am trying to write a script so that when i ftp to our server i can check if file X is there and depending on whether or not it is, then perform and action. You can't use IF/Then stmts once you are at the ftp> prompt so can someone please help me with an alternative.

See More: How can i perform a file check at ftp prompt

Report •

September 21, 2012 at 18:35:28
This may get you started:

:: 28433.bat
PUSHD "%~dp0"

SET /P ftp_user=Enter the FTP Userid: 
SET /P ftp_pass=Enter the FTP Password for %ftp_user%: 
SET /P filename=Enter required file name: 
SET not_found=550 %filename%: The system cannot find the file specified.
SET action=DIR
CALL :Construct_FTP_Script
ftp -s:ftp.script <Your FTP Server>|FINDSTR /I /C:"%not_found%">NUL
    SET action=GET
    CALL :Construct_FTP_Script
    ftp -s:ftp.script <Your FTP Server>
DEL ftp.script

 >ftp.script ECHO %ftp_user%
>>ftp.script ECHO %ftp_pass%
>>ftp.script ECHO %action% "%filename%"
>>ftp.script ECHO QUIT

Change <Your FTP Server> to your FTP server. I don't know what action you want to perform, so the above does a "GET" and stores the resulting file in the same directory as the batch file.

When your only tool is a hammer, every problem looks like a nail.

Report •

September 25, 2012 at 11:38:13
Now I am not an expert script writer so bare with me. Is this going to work in an MS Dos prompt. That is where I am accessing the ftp prompts.

Report •
Related Solutions

Ask Question