transfering file over tcp - TCP-IP

This is a discussion on transfering file over tcp - TCP-IP ; Hello all, I am a nertwork programming newbie. I am trying to write a client-server pair (in C on Solaris) such that the client should be able to transfer a file over TCP connection to the server. The only way ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: transfering file over tcp

  1. transfering file over tcp

    Hello all,

    I am a nertwork programming newbie. I am trying to write a
    client-server pair (in C on Solaris) 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


  2. Re: transfering file over tcp

    In article <1158682390.519280.20810@k70g2000cwa.googlegroups.c om>,
    wrote:

    >I am a nertwork programming newbie. I am trying to write a
    >client-server pair (in C on Solaris) 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?


    No, there is no function call for that.

    There are, though, several readily available libraries that are
    well suited for file transfer. See for example,

    http://en.wikipedia.org/wiki/SSH_file_transfer_protocol



    Dang, I'm forgetting the names of some of the best-known
    programs

  3. Re: transfering file over tcp


    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?


    Some operating systems have one, but they're much more difficult to use
    than just reading the file and writing to the socket.

    One piece of advice -- before you write a line of code, decide on the
    protocol you are going to use and document it on paper. It should be
    sufficiently detailed that someone else could write a server (using
    just your protocol document) and it would work with your client and
    vice versa.

    DS


  4. Re: transfering file over tcp

    In article <1158699853.355593.78900@i42g2000cwa.googlegroups.c om>,
    "David Schwartz" wrote:

    > 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?

    >
    > Some operating systems have one, but they're much more difficult to use
    > than just reading the file and writing to the socket.


    The system call is sendfile(), and it looks pretty simple to use. You
    give it the descriptor of a file open for reading, a descriptor of a
    stream open for writing, a starting offset, and a number of bytes to
    write.

    However, it's not clear how portable it is. It was introduced in
    FreeBSD, and has been added to Linux, but I don't think it's in POSIX or
    SUS.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  5. Re: transfering file over tcp

    Barry Margolin writes:

    > In article <1158699853.355593.78900@i42g2000cwa.googlegroups.c om>,
    > "David Schwartz" wrote:
    >
    > > 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?

    > >
    > > Some operating systems have one, but they're much more difficult to use
    > > than just reading the file and writing to the socket.

    >
    > The system call is sendfile(), and it looks pretty simple to use. You
    > give it the descriptor of a file open for reading, a descriptor of a
    > stream open for writing, a starting offset, and a number of bytes to
    > write.
    >
    > However, it's not clear how portable it is. It was introduced in
    > FreeBSD, and has been added to Linux, but I don't think it's in POSIX or
    > SUS.


    system call sendfile() may exists on many operating systems, but arguments
    differ on many. One example:

    NAME
    sendfile() - send the contents of a file through a socket

    SYNOPSIS
    #include

    sbsize_t sendfile(int s, int fd, off_t offset, bsize_t nbytes,
    const struct iovec *hdtrl, int flags);


    Then on some other OS:

    NAME
    sendfile -- send(1,2) a file to a socket

    LIBRARY
    Standard C Library (libc, -lc)

    SYNOPSIS
    #include
    #include
    #include

    int
    sendfile(int fd, int s, off_t offset, size_t nbytes,
    struct sf_hdtr *hdtr, off_t *sbytes, int flags);


    Then again on some OS:

    NAME
    sendfile - transfer data between file descriptors

    SYNOPSIS
    #include

    ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);



    / Kari Hurtta

+ Reply to Thread