Display a message if the server is prompting

Hello

i have to perform a sftp from server "A" to server "B"(remote server).
when i execute the sftp command it prompts for password.

right now we haven't establish the ssh key exchange so we have to dispaly a error message if it prompts for password.
how can i perform it please help