Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd public_html/crap
dir $FILE
quit
END_SCRIPT

Where the $ variable have corresponding values, so if I run this on the promt as check_file > check.txt, I can then just check the file size for the check.txt file and know if the file exists or not. Well good deal, But I want to do the above check in the same script, for example, something like

{
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd public_html/crap
dir $FILE
quit
END_SCRIPT
} > $CHECK_FILE
if $CHECK_FILE = 0 {
  # file does not exist, lets upload the file to the server
  }
else {
  # file exists on the server, rename the file on server before uploading
  }

but somehow, I cannot capture any information into the $CHECK_FILE. Anyone ?

What language you you trying to use? In the bourne, ksh, bash type shells, you do stuff like this:
FILE=/tmp/output.txt
date > $FILE
This does not change the value of FILE. In your first script you are using a here-document. The last line of your script is the end of the here-document. It does not need to be the end of the script. You can keep on going and do more stuff. Go to our FAQ section and read the article on automating ftp jobs. There are a lot of examples there.

I am using bourne shell.

I did go on the FAQ site but I dont see an example in which we are trying to capture output generated by a script commands into a variable. Notice the bold S! :). What I mean is, I need to capture output fromt the ftp command dir $FILE as this will tell me if the file exists on the ftp server.