Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello:
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 SERVER=xxx
SET USERNAME=xxx
SET PASSWORD=xxx
SET LOCALFILE=c:\Plasma
SET REMOTEPATH="/Slideshow"
SET REMOTEFILE1="testfile.jpg"
SET LOGFILE=ftplog.txt
SET TEMPFILE=$temp.txtREM -----Move to the local directory and execute cleanup------
cd %LOCALFILE%
del /q *.jpgREM -----Create a temp txt file that will serve as the FTP script------
echo open %SERVER% >%TEMPFILE%
echo %USERNAME%>>%TEMPFILE%
echo %PASSWORD%>>%TEMPFILE%
echo bin >>%TEMPFILE%
echo cd %REMOTEPATH% >>%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------
ftp -s:%TEMPFILE% >>%LOGFILE%
REM -----Delete FTP script --------------------
del %TEMPFILE%
exit
...Tomarak

don't you need "user" in this line?
echo %USERNAME%>>%TEMPFILE%might need to be
echo user %USERNAME%>>%TEMPFILE%

Hello:
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.
Thanks...
...Tomarak

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?

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?
Thanks...
...Tomarak

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 &?

Hello:
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."
Thanks...
...Tomarak

Tomarak,
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 %fBut in a batch file:
FOR %%f IN (*) DO ECHO File is named %%fBut that's the only place where you need %%. Environment variables, such as what you're using, don't need a double %%.

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.

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

![]() |
Extracting rows from mult...
|
Reading another file's si...
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |