Shell Script to connect to another server and copying files

Hi Unix Gurus,

I have a doubt reg file transfer. I have used the below script to connect to another server and find files having modified for the last 24 hours and have to move the file to another server.
While i tried i am getting authentication failed, destination path not found issue.

below is my code

ssh user@server1 <<EOT
cd /path/folder1
find . -mtime -1 
when do file
scp -rp $file user2@server2 /path2/folder2
done
EOT

I usually get this with a password change - check

ssh user@server1 'find /path/folder1 -mtime -1 -exec scp -rp {} user2@server2/path2/folder2'

but I not sure scp can't do such a thing.

Where do execute this command from? server2?

You need passwordless authentication to server2.