you lost me
Main Topics
Browse All TopicsHi,
Was wondering if there is a way to use variables in my text file? I declare variables in my batch by calling my 'setenv.cmd' file with all the declarations. Then in the .bat file I have a line:
ftp -i -s:cfm_ftp_script.txt
Then my cfm_ftp_script.txt file looks like below. I want to use the variables for 'server' 'ftpuser' etc..... Can I do that? I tried wrapping them with % and also prefix with $ but neither worked...
open server
ftpuser
ftppwd
lcd d:\hyperion\cfm
cd ..
cd ..
cd essbase111
ls -al
asc
get cfm_extract.txt
bye
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You create a script which will take the variables that you want to pass to the ftp.
Assume the batch file is called ftpgo.bat
If you enter them from the command line, and you wanted to enter the username, password, local cd path, remote cd path and file name:
username: fred
password: bert
local cd path: d:\hyperion\cfm
remote cd path: essbase111
filename: cfm_extract.txt
on the command line you would type:
ftpgo.bat fred bert d:\hyperion\cfm essbase111 cfm_extract.txt
in the batch file ftpgo.bat you would put:
@echo off
echo open server >temp.bat
echo %1 >>temp.bat ' %1 is the username (first value from command line)
echo %2 >>temp.bat ' %2 is the password (second value from command line)
echo cd %3 >>temp.bat
...
echo bye >>temp.bat
ftp -i -s:temp.bat
This will create a file called temp.bat which contains the script values you want.
It then calls the ftp running the script file you created.
What is in your "setenv.cmd" ? What you need to it basically like has been said above. I imagine you need:
@Echo off
setlocal
REM Save this as ftpscript.cmd or something
call setenv.cmd
rem Assuming now you have done in there set username= set password= etc.
echo %date% %time% Creating a script file in the temp dir
(echo open %server%
echo %username%
echo %password%
echo lcd %downloadpath%
echo cd ..
echo cd ..
echo cd essbase111
echo ls -al
echo asc
echo get cfm_extract.txt
echo bye ) > "%temp%\ftpscript.txt"
echo %date% %time% Now executing FTP
ftp -i -s: "%temp%\ftpscript.txt"
echo %date% %time% Completed
Business Accounts
Answer for Membership
by: jakethecatukPosted on 2009-09-25 at 08:21:25ID: 25423926
One simple way would be to output the variables you want to your text file and then concatenate the static FTP commands to the bottom of it.
The ftp_upload.bat batch file below would do what you want :)
ftp_upload.bat myserver myuser mypassword
cfm_ftp_script-static.txt would contain the following: -
lcd d:\hyperion\cfm
cd ..
cd ..
cd essbase111
ls -al
asc
get cfm_extract.txt
bye
Select allOpen in new window