transfering a file over TCP
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > transfering a file over TCP




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    transfering a file over TCP  
shilpa.saraogi@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-19-06 06:32 PM

Hello all,

I am a nertwork programming newbie. I am trying to write a
client-server pair such that the client should be able to transfer a
file over TCP connection to the server.

The only way I know of, is to open the file, read into buffer and write
into the socket. Is there any function call to just transfer the file?

Thank you
Shilpa






[ Post a follow-up to this message ]



    Re: transfering a file over TCP  
Mikko Rauhala


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-19-06 06:32 PM

On 19 Sep 2006 09:08:44 -0700, shilpa.saraogi@gmail.com
<shilpa.saraogi@gmail.com> wrote:
> The only way I know of, is to open the file, read into buffer and write
> into the socket. Is there any function call to just transfer the file?

Not portably without some utility library or another. Some systems might
have calls like sendfile which are designed for this purpose, however
you should not use them in portable programs (or at least you should
fall back at compile time to a read/write solution).

--
Mikko Rauhala   - mjr@iki.fi     - <URL:http://www.iki.fi/mjr/>
Transhumanist   - WTA member     - <URL:http://www.transhumanism.org/>
Singularitarian - SIAI supporter - <URL:http://www.singinst.org/>






[ Post a follow-up to this message ]



    Re: transfering a file over TCP  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-19-06 06:32 PM

"shilpa.saraogi@gmail.com" <shilpa.saraogi@gmail.com> writes:

> Hello all,
>
> I am a nertwork programming newbie. I am trying to write a
> client-server pair such that the client should be able to transfer a
> file over TCP connection to the server.
>
> The only way I know of, is to open the file, read into buffer and write
> into the socket.

This is basically what you must do.

But you should probably add a EOF protocol (eg: write the file size
before sending the data).  You may also want to transfer several files
(eg sending the file directory/name and perhaps other attributes such
as owner, access rights, etc).

Now, TCP corrects some errors, but it normally computes a 2-byte check
sum on each packet, so the probability to have a undetected bad packet
is still rather high.  And the more so when you transfer long files.

So, I would add a more sophisticated error detection algorithm
(eg. doing md5sums on each 100 KB or 1 MB blocks).


Often, you want to get the directory listing of the remote side before
sending or receiving a file.  So you need to add some protocol to send
such commands and transfer directory "files".

Sometimes you don't want the file data to be sent in clear over TCP
either. Anybody on the network could see it...  So you may want to
encrypt the data, using ssl perhaps?


Are you aware that there is already this FTP protocol (and some other
ISO file transfer protocols), and implementations, in addition to scp
and sftp?



> Is there any function call to just transfer the file?

In Linux, there's sendfile(2). There's no recvfile though.

Other Unixes often implement sendfile  with  different  semantics
and prototypes. It should not be used in portable programs.

--
__Pascal Bourguignon__                     http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.





[ Post a follow-up to this message ]



    Re: transfering a file over TCP  
Mark Rafn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-19-06 06:32 PM

shilpa.saraogi@gmail.com <shilpa.saraogi@gmail.com> wrote:
>I am a nertwork programming newbie. I am trying to write a
>client-server pair such that the client should be able to transfer a
>file over TCP connection to the server.

Why?  If this is just a learning excercise, fine.  If it's for production us
e,
there are LOTS of existing ways to do this, and you should almost certainly
reuse one.

>The only way I know of, is to open the file, read into buffer and write
>into the socket.

Yup.  And probably with a protocol for transferring metadata (filename, size
,
permissions?), along with partial transfers or multiple file handling.

>Is there any function call to just transfer the file?

system("scp filename remote:remotefilename);
--
Mark Rafn    dagon@dagon.net    <http://www.dagon.net/>





[ Post a follow-up to this message ]



    Re: transfering a file over TCP  
Nils O. Selåsdal


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-20-06 06:32 AM

shilpa.saraogi@gmail.com wrote:
> Hello all,
>
> I am a nertwork programming newbie. I am trying to write a
> client-server pair such that the client should be able to transfer a
> file over TCP connection to the server.
>
> The only way I know of, is to open the file, read into buffer and write
> into the socket. Is there any function call to just transfer the file?

That's the usual way, and indeed very simple too.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:34 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register