Page 1 of 1

Help using CD with a variable for use with FTP script

Posted: 26 Aug 2010 10:59
by looey
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!

Re: Help using CD with a variable for use with FTP script

Posted: 26 Aug 2010 12:59
by alan_b
I suggest you type the content of LatestBuild.txt in a code box to show what needs to be parsed.

Code: Select all

NB This is a code box, opened by clicking the Code button at the top of a reply. 


Alan

Re: Help using CD with a variable for use with FTP script

Posted: 26 Aug 2010 18:17
by looey
Hi Alan,

Thank you for your reply.

The below is an example of what is typically in the LatestBuild.txt file.

Code: Select all

Build 022 (2010-08-25)

Re: Help using CD with a variable for use with FTP script

Posted: 27 Aug 2010 02:53
by alan_b
You said
"parse the content of LatestBuild.txt and it into a variable. ... I want to use it as a directory name."
It is not self evident to me which portion of "Build 022 (2010-08-25)" is the directory name.

Alan

Re: Help using CD with a variable for use with FTP script

Posted: 27 Aug 2010 03:03
by orange_batch
Come on Alan, you're supposed to know exactly what each of these people's working environment is! :lol:

Re: Help using CD with a variable for use with FTP script

Posted: 27 Aug 2010 09:52
by looey
HI Alan,

My apologies, it's been awhile since I've done any sort of DOS work and my terminology usage is pretty rusty.

The entire contents of the LatestBuild.txt (which is only one line) would be the directory name that I need to get into.

So, I would need to get into

ftp>Level 1\level 2\level 3\level 4\Build 022 (2010-08-25)

And then I would run an mget to grab all of the files within the "Build 022 (2010-08-25)" folder. If I could grab the folder, that would be even better, though I'd still have to be able to navigate into the folder to uncompress the files.

Really appreciate the help. It *seems* to me like I'm doing the right thing with %ThisDir%, but it doesn't work, so I'm a bit stumped.

Re: Help using CD with a variable for use with FTP script

Posted: 28 Aug 2010 05:11
by alan_b
If text is
C:\Level 1\level 2\level 3\level 4\Build 022 (2010-08-25)
then you can navigate to it with
CD /D C:\Level 1\level 2\level 3\level 4\Build 022 (2010-08-25)

You have a different ball game with
ftp>Level 1\level 2\level 3\level 4\Build 022 (2010-08-25)

I have no relevant experience so I am out

Regards
Alan