There exists a way in the shell to do different kinds of checks, like if a file exists:
$ if [ -e some-file ]; then echo exists; fi
exists
It looks like [ is a part of the syntax. But it's not. You can find the executable at /usr/bin/[ (although it may be implemented as a built-in). The long name is test. So, [ -e some-file ] is a command with 3 arguments. And there can be any other command in place of the square brackets:
$ if grep ^root: /etc/passwd &> /dev/null; then echo why wouldn\'t it be there?; fi
Next, here's how you can execute commands on a remote machine:
$ ssh user@host echo hello from the other side
hello from the other side
Now then, let's put it all together:
$ if ssh user@host [ -e some-file ]; then echo exists; fi
exists
Or:
$ if ssh user@host /usr/bin/[ -e some-file ]; then echo exists; fi
exists