check if remote file exists

Hi

Does anybody know how I can check if a file exists on a remote machine

i.e. see bellow, this doesn't work by the way and if tried countless variations on this

#!/bin/sh

hostname=server56

if [ -f `ssh $hostname '/usr/local/file'` ]; then
echo file exists
else
echo file doesn't exist
fi

Any help on this would be greatly appreciated

One way (not tested):

#!/bin/sh

hostname=server56

if [ -n `ssh $hostname 'ls /usr/local/file 2>/dev/null'` ]; then
echo file exists
else
echo file doesn't exist
fi

Here's another way:

#!/bin/sh

#
# Name:
#       testfile
#
# Usage:
#       ./testfile "/dir/and file to test for.txt"
#
# Notes:
#       Quotes needed when testing for names with whitespace, etc.
#       Be certain to:
#               > chmod 700 testfile
#       and perform any setup needed for ssh such as key generation and
#       proper placment on the remote computer
#

hostname=mike@ram

echo $hostname
if ssh $hostname 'ls "'$1'" >/dev/null'; then
        echo "file '"$1"' exists";
        echo "byebye";
        exit;
else
        echo "file '"$1"' doesn't exist";
fi
echo "finito!"