Ftp mget not working when used in script
I am trying to get multiple files from a Unix machine using MS DOS ftp script (Windows 7). I'm new to this, so I was trying to modify the online example. The code looks like this:
@echo off
SETLOCAL
REM ##################################
REM Change these parameters
set FTP_HOST=host
set FTP_USER=user
set FTP_REMOTE_DIR=/users/myAcc/logFiles
set FTP_REMOTE_FILE=*.log
set FTP_LOCAL_DIR=C:\Temp
set FTP_TRANSFER_MODE=ascii
REM ##################################
set FTP_PASSWD=password
set SCRIPT_FILE=%TEMP%\ftp.txt
(
echo %FTP_USER%
echo %FTP_PASSWD%
echo %FTP_TRANSFER_MODE%
echo lcd %FTP_LOCAL_DIR%
echo cd %FTP_REMOTE_DIR%
echo prompt
echo mget %FTP_REMOTE_FILE%
) > %SCRIPT_FILE%
ftp -s:%SCRIPT_FILE% %FTP_HOST%
del %SCRIPT_FILE%
ENDLOCAL
However, when I run this, the command mget
fails and the following output is displayed:
Note: The output from the rest of the script shows that all of the previous steps are working as expected. I even added commands ls
to check that the script is in the correct directory.
...
ftp> mget *.log
200 Type set to A; form set to N.
mget logFile1_SystemOut_22-01-13.log? mget logFile2_SystemOut_22-01-13.log? mget
logFile3_SystemOut_22-01-13.log? ftp>
I tested it manually by repeating the same steps and it works fine - no problem and the files will be successfully transferred to the C: \ Temp directory.
I have checked numerous forums and other sites and I see no reason why it should behave like this. Any guidance as to why this is not working in a script would be great!
thank
source to share
ftp -i -s:%SCRIPT_FILE% %FTP_HOST%
also worked for me.
another option is to switch the prompt to the ftp script before you call mget (which is what you do) and I read somewhere too mget -i
.
but note: prompt
the ftp script will re-enable the prompt if it was disabled before. so use either ftp -i
OR prompt
, but not both!
you can check if your script works otherwise by repeating several times y
in the ftp script after mget, so it answers yes to the prompts as they come up.
source to share