Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
1  
Which version of Windows? If it's Vista or 7 it could be a permissions issue, though your edit detailing the exact symptoms doesn't fit with that diagnosis. –  ChrisF Jan 20 '10 at 23:18

3 Answers 3

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.

share|improve this answer
    
prints current directory correctly. –  Tommy Jan 20 '10 at 22:51
up vote 1 down vote accepted

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...

share|improve this answer

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

share|improve this answer
    
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 '10 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!) –  William Hilsum Jan 20 '10 at 23:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.