Use Net::EasyTCP.
It has a "portpassword" you can set, so only clients knowing
the password can connect. It also encrypts, although RSA seems
to be too slow for me, but it does work.
Look at an example here:
EasyTCP
You can carry on any kind of conversation with this module, not just
file transfer. Look at the example in the pod.