ftp script works in CMD line but not from bat

October 27, 2009 at 14:32:39
Specs: Windows XP

I have an ftp script that runs in the command line but not from within a batch file. Anyone have any ideas why? Below is the script. Any tips would be appreciated...

REM -----Set variables to be written to the temp txt file that will serve as the FTP script------

SET REMOTEFILE1="testfile.jpg"
SET LOGFILE=ftplog.txt
SET TEMPFILE=$temp.txt

REM -----Move to the local directory and execute cleanup------

del /q *.jpg

REM -----Create a temp txt file that will serve as the FTP script------

echo open %SERVER% >%TEMPFILE%
echo bin >>%TEMPFILE%
echo prompt >>%TEMPFILE%
echo mget %REMOTEFILE1% >>%TEMPFILE%
echo quit >>%TEMPFILE%
echo >>%LOGFILE%
echo Transfering %REMOTEFILE% to %LOCALFILE% at %DATE% %TIME% >>%LOGFILE%

REM -----Execute FTP script------


REM -----Delete FTP script --------------------




See More: ftp script works in CMD line but not from bat

Report •

October 27, 2009 at 22:51:24
don't you need "user" in this line?

might need to be

echo user %USERNAME%>>%TEMPFILE%

Report •

October 28, 2009 at 07:47:36

Thanks... I do have a username. I put xxx for the values so everyone won't have access to my ftp server... :)

The script works if I paste it into a command line... It just won't work from a .bat file.

I read another article that said you needed %% (double percents) before the variables in a script but im not sure which ones to put them before.



Report •

October 28, 2009 at 10:38:46
I think nbrane is saying you may need to put the word "user" in front of your username.

But I don't think that's what the problem is. You just type the username (without the "user" command) at the User: prompt after you type the Open command.

What is the name of your batch file? (Not ftp.bat by any chance?)

And what is the error you are getting?

Report •

Related Solutions

October 28, 2009 at 10:44:05
The name of the batch file is PlasmaNorth.bat. I don't get any errors.

If I paste the commands in an open cmd prompt window it works fine and fills up the folder with the requested .jpg files.

But if I put it in a .bat file and run it, it just deletes everything in the folder (as requested) then puts a log file in the folder... nothing else. :( Any Ideas?



Report •

October 28, 2009 at 11:17:24
I can't see anything wrong with the script. Could it be that the real values of the variables SERVER, USERNAME or PASSWORD contain any special characters such as % or &?

Report •

October 28, 2009 at 12:20:47

All the file names contain alpha characters only. Here is a comment I found on another post... Do you think it may help with my issue? If so can you tell me which variables need the %% to work?

"Replace %X with %%X as inside batch files the For variables must be prefixed by a pair of %% while just one is required when the statement is typed at prompt."



Report •

October 28, 2009 at 16:03:31

You don't have any FOR loop variables in your script, so the %% doesn't apply.

Just for information, the advice that you quote is only applicable to FOR loops, e.g.:

To go through all files:

On the command line:
FOR %f IN (*) DO ECHO File is named %f

But in a batch file:
FOR %%f IN (*) DO ECHO File is named %%f

But that's the only place where you need %%. Environment variables, such as what you're using, don't need a double %%.

Report •

October 28, 2009 at 16:07:34
To troubleshoot your issue, I suggest liberally spraying tracing statements, such as a few echo statements to tell you what's going on and a few DIR statements to show you what files have so far been created. Also, maybe, replace FTP with the full pathname (probably C:\Windows\system32\ftp.exe) just in case there is another ftp somewhere.

Report •

October 30, 2009 at 05:00:35
hey, lots of bandwidth on this one!
one other thing i noticed. looking at my "login"
ftp script, is using option "-n". (see: ftp -? for
details). it sounds like your script has got beyond this
point however. mine doesn't use variables, so the
percents might still be an issue with you. also, this
is run on old winME cp, so...
here is my test script (ttt is ftp script out)

echo open {hostname} > ttt
echo user {username} >> ttt
echo {passwd} >> ttt
:just some dummy commands here to see if worked...
echo dir >> ttt
echo quit >> ttt
ftp -n -s:ttt

Report •

Ask Question