abcdxyz
abcdxyz

Reputation: 11

unable to send binary data over unix tcp socket

I'm trying to implement ftp commands GET and PUT thru a UNIX socket for file transfer using usual functions like fread(), fwrite(), send() and recv().

It works fine for text files, but fails for binary files (diff says: "binary files differ")

Any suggestions regarding the following will be appreciated:

  1. Are there any specific commands to read and write binary data?
  2. Can diff be used to compare binary files?
  3. Is it possible to send the binary parts in chunks of memory?

Upvotes: 1

Views: 1083

Answers (2)

unwind
unwind

Reputation: 399723

If you're reading from a file and then writing the file's data to the socket, make sure you open the file in binary mode.

Yes, diff can be used to compare binary files, typically with the -q option to suppress the actual printing of differences, which rarely makes sense for binary files. You can also use md5 or cmp if you have them.

Upvotes: 0

Liv
Liv

Reputation: 6124

the FTP protocol has 2 modes of operation: text and binary. try it in any FTP client -- I believe the commands for switching in between are ASCII and BIN. The text mode has only effect from what I recall on the CR/LF pairs though.

Upvotes: 3

Related Questions