Check if file exists via ssh in ssh (nested)

I'm using redhat and have an odd issue with a nested ssh call.

ssh -i ~/.ssh/transfer-key -q transfer@fserver1 [[ -f /home/S/outbox/complete ]] 
&& ssh -i ~/.ssh/transfer-key transfer@fserver1 "ssh -i ~/.ssh/sftp-key sftpin@10.0.0.1 [[ ! -f /datain/complete]]" 
&& ssh -i ~/.ssh/transfer-key transfer@fserver1 "scp -i ~/.ssh/sftp-key /home/S/outbox/* sftpin@10.0.0.1:/datain" 
&& ssh -i ~/.ssh/transfer-key transfer@server1 "rm /home/S/outbox/*"

what this is doing is checking if a complete file is in an outbox, if so, ssh to a transfer server, executing a second ssh and checking if a file is 'not' present on the destination and if no, sending the files. I'm restricted to which ids and servers can be used, hence this convoluted method.

I'm getting a syntax error on the part where I'm checking if the file doesn't exist on the target.

ksh: syntax error at line 1: `[[' unmatched

Any ideas how to check this in an embedded ssh call?

Thanks in advance

---------- Post updated at 10:19 AM ---------- Previous update was at 10:13 AM ----------

doh... missed a space at the end before ]]
only when I posted it here was it obvious.

If you tunnel to this machine a lot, did you know you can setup ssh to do it for you.

So lets say this machine 10.0.0.1 is called saysdata.

If you put something like the below in your ~/.ssh/config file:

host fserver1
user transfer
IdentityFile ~/.ssh/transfer-key

host saysdata
user sftpin
IdentityFile ~/.ssh/sftp-key
ProxyCommand ssh fserver1 -W %h:%p

I haven't tried this with alternate identityfiles and this will require you to bring the sftp-key to your local machine. Perhaps someone with more experience in this area knows of a way to keep the identity file on the jump box.

Anyway the result should be that you will be able to simply type:

ssh saydata "[[ -f /datain/complete ]]"
scp fserver:/home/S/outbox saydata:/datain
ssh fserver1 "rm /home/S/outbox/*"

Without worrying about identity files or nested ssh and scp commands. Much easier and probably worth a little mucking around to get working if you do it semi-regular.

Note that ssh is running a shell on the remote end, so the rules are most likely bash or ksh as sh does not do [[]], but not ssh. I guess 'ssh' as 'secure shell' is a misnomer, since it is not a shell but a remote execution tool.