You either need to use a library such as ftputil or encode the file in some way such as such as UUENCODE.
Alternatively you will have to implement your own protocol with separate transactions to send the file name and size then the contents. i.e.
- Client gets the file path then checks the size plus splits off the basename.
- Client sends the file base name and size in a pre-formatted manner.
- Server receives and interprets the above information then opens the file called base name for write.
- Client sends the binary data.
- Server writes binary data to open file.
- Both compute the MD5, or similar, for the file and exchange information to make sure it matches.
Note that the above does not cover handling problems such as lost data, ASCII only links, corruption, sending as blocks, etc. Bear in mind that FTP has been in active use and development since 1971 with fundamental change suggested as late as 1998.