Problem with ssh script

I want to execute below the script for remote server.i am not able to execute below the script please help me urgent for this issue.i getting below the error

ssh user@server<<EOJ
cd path
for i in *
do
     echo $i
done
EOJ
Pseudo-terminal will not be allocated because stdin is not a terminal.
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
You have new mail.
stty: : Invalid argument



stty: : Invalid argument

Have you tried something like:

 ssh user@server "cd path; for i in *; do echo \$i; done"