Help using CD with a variable for use with FTP script
Posted: 26 Aug 2010 10:59
Hello,
I am trying to write a BAT file that will do the following:
1. Connect to an FTP server and navigate to a specific folder
2. Grab a specific file in the folder (LatestBuild.txt). This text file contains one line, which is the string name of the newest build that I need to grab
3. Turn that content of LatestBuild.txt into a variable
4. navigate the folder with the latest build (the name of the folder corresponds to the text in the textfile)
5. grab all files in the folder from step 4
I'll probably write a VBScript to uncompress the files that were grabbed in step 5 in their now local directory.
What I have so far:
A BAT file (kickoff.bat) that basically is one line:
ftp -s:try.txt <myServer>
try.txt then logs into the server and navigates to the folder where the LatestBuild.txt lives:
USER
PASSWORD
bin
ascii
cd level 1
cd level 2
cd level 3
cd level 4
get "LatestBuild.txt"
goto :eof
Here is where I get stuck.
I have a script can parse the content of LatestBuild.txt and it into a variable. I just can't seem to figure out how to turn that variable into a string that DOS understands when I want to use it as a directory name.
What I have so far ("Check Latest Build Number.txt")
@echo off & setlocal
For /F "tokens=*" %%i in (LatestBuild.txt) do call :doSomething "%%i"
goto :eof
:doSomething
echo Now working with "%~1" string
Set "ThisDir=%~1"
:: do something with %ThisDir%
cd %ThisDir%
Even if I put %ThisDir% in quotes on the last line, I don't go anywhere.
The second issue is figuring out how to kickoff this second part to run after I grab the LatestBuild.txt. If I could solve these two issues, then step 5 would be simple.
Can anyone provide any insight? I haven't done any work in DOS in ages, so I am pretty rusty. I'm not even 100% sure that my approach is correct (ideally I'd like to hide the Username and Password somehow).
Thank you so much!
I am trying to write a BAT file that will do the following:
1. Connect to an FTP server and navigate to a specific folder
2. Grab a specific file in the folder (LatestBuild.txt). This text file contains one line, which is the string name of the newest build that I need to grab
3. Turn that content of LatestBuild.txt into a variable
4. navigate the folder with the latest build (the name of the folder corresponds to the text in the textfile)
5. grab all files in the folder from step 4
I'll probably write a VBScript to uncompress the files that were grabbed in step 5 in their now local directory.
What I have so far:
A BAT file (kickoff.bat) that basically is one line:
ftp -s:try.txt <myServer>
try.txt then logs into the server and navigates to the folder where the LatestBuild.txt lives:
USER
PASSWORD
bin
ascii
cd level 1
cd level 2
cd level 3
cd level 4
get "LatestBuild.txt"
goto :eof
Here is where I get stuck.
I have a script can parse the content of LatestBuild.txt and it into a variable. I just can't seem to figure out how to turn that variable into a string that DOS understands when I want to use it as a directory name.
What I have so far ("Check Latest Build Number.txt")
@echo off & setlocal
For /F "tokens=*" %%i in (LatestBuild.txt) do call :doSomething "%%i"
goto :eof
:doSomething
echo Now working with "%~1" string
Set "ThisDir=%~1"
:: do something with %ThisDir%
cd %ThisDir%
Even if I put %ThisDir% in quotes on the last line, I don't go anywhere.
The second issue is figuring out how to kickoff this second part to run after I grab the LatestBuild.txt. If I could solve these two issues, then step 5 would be simple.
Can anyone provide any insight? I haven't done any work in DOS in ages, so I am pretty rusty. I'm not even 100% sure that my approach is correct (ideally I'd like to hide the Username and Password somehow).
Thank you so much!