无法通过 unix tcp 套接字发送二进制数据
我正在尝试通过 UNIX 套接字实现 ftp 命令 GET 和 PUT,以便使用 fread()、fwrite()、send() 和 recv() 等常用函数进行文件传输。
它适用于文本文件,但不适用于二进制文件(diff 说:“二进制文件不同”)
任何有关以下内容的建议将不胜感激:
- 是否有任何特定命令来读取和写入二进制数据?
- diff可以用来比较二进制文件吗?
- 是否可以在内存块中发送二进制部分?
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:
- Are there any specific commands to read and write binary data?
- Can diff be used to compare binary files?
- Is it possible to send the binary parts in chunks of memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FTP 协议有 2 种操作模式:文本和二进制。
在任何 FTP 客户端中尝试一下——我相信用于切换的命令是 ASCII 和 BIN。不过,文本模式仅对我记得的 CR/LF 对有影响。
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.
如果您要读取文件,然后将文件的数据写入套接字,请确保以二进制模式打开文件。
是的,diff 可用于比较二进制文件,通常使用 -q 选项 抑制实际打印差异,这对于二进制文件几乎没有意义。您还可以使用 md5 或 cmp 如果你有的话。
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.