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