I forgot to tell you. There is no function to know received data is a file data or just a text.
I suggest you to see RFC959 (File Transfer Protocol) as an example.

http://datatracker.ietf.org/doc/rfc959/