We help IT Professionals succeed at work.

Sending a file across a network

zxcvzxcv
zxcvzxcv asked
on
Medium Priority
313 Views
Last Modified: 2010-04-02
Hi,
I need to be able to send a file across a network using sockets and C/C++ and BSD environment. My current method involves simply reading the binary data of the file and sending that over a socket. Then having the other end write that into a new file. However that's alot of data traveling through the socket. This seems prone to buffer overflows because it seems hard to set a limit for the buffer (this could result in files being to big to transfer). Is there a better way of sending documents and programs over a network?
Comment
Watch Question

if you use stream type sockets (tcpip), the socket
layer itself guarantees that all the data will be send
correctly. If a chunk of data is too large to be send
in one sweep, the transmission layer chops it up in
smaller segments and blocks until all has been sent
to its peer. No need to worry ...

Author

Commented:
ok, well do you know how it's done with professional file transfer protocols like FTP?
If you want a detailed description on the ftp protocol,
read the following:

   http://www.freesoft.org/CIE/RFC/959/index.htm

kind regards,

Jos

Author

Commented:
I've read that and I can't seem to see how a file is transfered. (eg: Is it just raw binary data?)
Yes it is, the file size is determined and transfered
to the other side (using htonl()), then the file is read, chunk by chunk, while all chunks are being transfered to
the other world; that's basically all there is to it.

FTP can add compression and CRC checks, but what I wrote
above is about it... the tcpip layer takes care of
correctly sending those chunks and reports about any
possible failure (network down etc.)

kind regards,

Jos

Explore More ContentExplore courses, solutions, and other research materials related to this topic.