sending files over a network

Discussion in 'Ruby' started by Pieter Breed, Apr 1, 2006.

  1. Pieter Breed

    Pieter Breed Guest

    Hi All,

    I am relatively new to Ruby and I am considering using it for a little
    itch of my own I want to scratch. It deals with sending files over a
    network, but in a one-computer-to-one-computer way, not swarming like
    with torrents.

    My question is two-fold: What is, in general, the better way of sending
    files across a network like this. By better I mean appropriate for
    files that may be both very long and very short? Some error checking
    also needs to be done so the files don't corrupt. I realise this is not
    really ruby specific, but bear with me please.

    How would you do/implement this in Ruby? If I was more familiar with
    either Ruby or network programming I could probably bootstrap my
    knowledge, but it seems I just don't know enough.

    Regards,
    Pieter Breed
    Pieter Breed, Apr 1, 2006
    #1
    1. Advertising

  2. Pieter Breed

    f3l Guest

    Pieter Breed wrote:
    > Hi All,
    >
    > I am relatively new to Ruby and I am considering using it for a little
    > itch of my own I want to scratch. It deals with sending files over a
    > network, but in a one-computer-to-one-computer way, not swarming like
    > with torrents.


    why not useing ftp?

    >
    > My question is two-fold: What is, in general, the better way of sending
    > files across a network like this. By better I mean appropriate for
    > files that may be both very long and very short? Some error checking
    > also needs to be done so the files don't corrupt. I realise this is not
    > really ruby specific, but bear with me please.
    >
    > How would you do/implement this in Ruby?


    u dont need to, its been done for you before, lots fo times, just find
    one implementation that suits your needs, and stick to it.

    > If I was more familiar with
    > either Ruby or network programming I could probably bootstrap my
    > knowledge, but it seems I just don't know enough.
    >
    > Regards,
    > Pieter Breed
    f3l, Apr 1, 2006
    #2
    1. Advertising

  3. Pieter Breed

    Pieter Breed Guest

    Uhm, thanks... I didn't think of that...

    actually I really meant to ask what I asked in the first place... Sorry
    for being bitchy, but I your answer was kind of silly.

    Pieter
    Pieter Breed, Apr 1, 2006
    #3
  4. Pieter Breed

    Guest

    On Sun, 2 Apr 2006, Pieter Breed wrote:

    > Uhm, thanks... I didn't think of that...
    >
    > actually I really meant to ask what I asked in the first place... Sorry
    > for being bitchy, but I your answer was kind of silly.
    >
    > Pieter


    check out ruby-sendfile - you'll have a tough time getting faster.

    regards.

    -a
    --
    share your knowledge. it's a way to achieve immortality.
    - h.h. the 14th dali lama
    , Apr 1, 2006
    #4
  5. If you know how to work with files, and how to set up connections
    (TCPServer/TCPSocket) you know enough to send a file over network with
    Ruby. Performance will be network-limited, so don't worry too much
    about it.

    You can use MD5/SHA1 for additional error checking, for error checking,
    tough TCP has this feature on its own.

    pseudocode ( as in - not tested but with a couple of fixes should
    probably work )

    - sender:
    name="file.txt"; len = File.new(name).stat.size.to_s
    socket = TCPSocket.new('remote.host.org', 6666)
    socket.puts name
    socket.pits.len
    socket.write File.read(name)
    socket.close

    - reciever:
    socket = TCPServer.new('0.0.0.0', 6666).accept
    name = socket.gets
    len = socket.gets
    File.open(name, "wb") { | fl | fl.write (socket.read len.to_i ) }
    socket.close
    ---

    HTH
    Konstantin Levinski, Apr 2, 2006
    #5
  6. Pieter Breed

    Pieter Breed Guest

    Thanks Konstantin, that is really helpful and I will give it a bash

    Regards,
    Pieter
    Pieter Breed, Apr 2, 2006
    #6
  7. btw, depending on your requirements you might want to have a look at
    http://rio.rubyforge.org/ -
    it gives IO, File, Dir and sevral others a simple consistent interface
    - in case you want to work with directories and files and a lot
    Konstantin Levinski, Apr 3, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Wilson
    Replies:
    7
    Views:
    5,195
    Paul Wilson
    Jun 21, 2004
  2. Jane Davis

    Network Service account over network

    Jane Davis, Jun 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    429
    Kevin Spencer
    Jun 22, 2005
  3. Steve Line
    Replies:
    8
    Views:
    658
    Tony Morris
    Jan 14, 2004
  4. Jan Li?e
    Replies:
    6
    Views:
    755
    Steve Horsley
    Feb 8, 2004
  5. Frank Millman
    Replies:
    8
    Views:
    382
    Frank Millman
    Jul 23, 2007
Loading...

Share This Page