SSH and SFTP

remotePath=$1
fileName=$2
remoteUser=$3
remoteServer=$4
 
echo " if [ -r $remotePath/$fileName ]; then echo '0'; else echo '1'; fi " > temp_command.log
command1=`cat temp_command.log`
ssh $remoteUser@$remoteServer $command1
rm temp_command.log

Above code is to check whether the file in remote server is exist. It was done by using "ssh".
Due to requirement constraint, I am not allowed to use "ssh". I have to use "sftp".
Is it possible to check whether the remote file is exist or not by using "sftp" ?

Thanks.. :slight_smile:

one solution is to read the sftp log. you would see something like... if not found

sftp> ls abc.txt
Couldn't stat remote file: No such file or directory
Can't ls: "/abc.txt" not found
sftp>

i'm kinda wonder why sftp was allowed but ssh was not though it uses same protocol?