5

I have a .bat script with ftp commands (all in one) similar to this. See 5th down:FTP - Resolving Environment Variables - Creating FTP script on the fly at runtime and using variables within the FTP script

When I run the .bat from command line, everything works well. The files are transferred (in my case) from the server to my computer.

However, when I run this same .bat file by double clicking, it no longer interprets the ftp script correctly.

All other .bat files seem to work the same if they are double clicked vs. called from command line. Will that not work here? If so, why not?

EDIT:
It seems the problem is when it reaches the first ftp command that uses a variable.
For example it will open and connect fine, but then my next command is a get with a variable for the file name. It can't seem to read the variable name and just calls get. However, I do not see this issue when I call the bat from the cmd line....

EDIT
Issue fixed, see my answer below.

Thank You.

0

3 Answers 3

2

I would guess that your current directory is set wrong when double clicking on the .bat file and that is what is causing it not to find the FTP script.

Try adding echo %CD% to the batch file and see what it prints in each case.

1
  • prints current directory correctly.
    – Tommy
    Jan 20, 2010 at 22:51
2

This is very hard without knowing how the script is failing.

The main difference between running from a command prompt window and double click would be the working directory.

You cannot change this on normal batch files, but you can create a shortcut to the batch file and change the Start in: directory there.

alt text

2
  • It looks like the first time it hits a ftp command with a variable, i.e. get %MY_FILE% it doesn't read the variable....when double clicking only?
    – Tommy
    Jan 20, 2010 at 22:54
  • To be honest, I am not really sure (and too tired to try this out now for you - sorry), I recommend putting in a pause command after it generates the .ftp file and look at its contents to make sure it is there and the contents are good. If you are still having problems, please say and I will try and help you further in the morning. (maybe write a comment to nudge/remind me!) Jan 20, 2010 at 23:22
1

ANSWER:
My variables were declared before the for loop that saves the ftp commands in a temp file, and then replaces the variables with the values. So at that point, there were no variables to replace the ones used in the ftp script.

It only appeared it was working from the command line because once I called it the first time it probably errored there, but if I called it again without closing the console, the variables were now stored in memory. From there it then looked like it was always working from the console.

Once they were stored in memory it didn't matter that the for loop was before the variables. The variables were now stored in memory after opening it the first time.

When double clicking, it was opening for the first session, every time, and the variables were deleted in memory after it closed automatically. So in this case it opened and closed, each time I double clicked it.

Opening for the first session vs. calling it again in the same console without closing it out was the main difference here. Calling it the first time, the variables would be saved BEFORE after the ftp script was already created.

Please feel free to edit this if you can make it clearer...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .