Then error while running script remotely

facing issue with then error while running a local script aginst a remote server. i facing the same issue in multiple scripts. So what i am missing here or what is needed.

#!/bin/ksh
echo "enter the filename"
read file
if [ -f "$file" ]
then
echo "file exists"
else
echo "file does not exists"
fi

running locally works fine, but remotely showing `then' is not expected.

i'm running like this

ssh username@hostname ksh -s < scriptname