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 •

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

:: 28433.bat
@ECHO OFF &SETLOCAL
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
IF /I !ERRORLEVEL! NEQ 0 (
    SET action=GET
    CALL :Construct_FTP_Script
    ftp -s:ftp.script <Your FTP Server>
)
DEL ftp.script
POPD
EXIT /B

:Construct_FTP_Script
 >ftp.script ECHO %ftp_user%
>>ftp.script ECHO %ftp_pass%
>>ftp.script ECHO %action% "%filename%"
>>ftp.script ECHO QUIT
GOTO :EOF

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 •

#2
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