File copy blues

Hi

How do I copy an entire directory from one place to another?

At the moment I am copying the names of all the sub directories then
creating them in the new location, then recursively going through each
of the sub directories and copying the files to the new directories
created.

This seems like a long way around.

Plus I also want to be able to copy the entire directory to another
machine - I was thinking of opening a socket connection to a listener on
the target machine and trying to copy the files that way.

Any thoughts?

Kingsley

At the moment I am copying the names of all the sub directories then
creating them in the new location, then recursively going through each
of the sub directories and copying the files to the new directories
created.

Well 1.8 has a module fileutils

···

#
  # Options: preserve noop verbose
  #
  # Copies +src+ to +dest+. If +src+ is a directory, this method copies
  # all its contents recursively. If +dest+ is a directory, copies
  # +src+ to +dest/src+.
  #
  # +src+ can be a list of files.
  #
  # # Installing ruby library "mylib" under the site_ruby
  # FileUtils.rm_r site_ruby + '/mylib', :force
  # FileUtils.cp_r 'lib/', site_ruby + '/mylib'
  #
  # # Examples of copying several files to target directory.
  # FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
  # FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop, :verbose
  #
  def cp_r( src, dest, options = {} )

For 1.6 it can be found in ruby_shim

    http://raa.ruby-lang.org/list.rhtml?name=shim-ruby16_18

Guy Decoux

For copying to the remote machine, I’d say ‘rsync’ is the best tool. It’s
not a Ruby program or library, but you can run it using system() of course.
It runs over ssh.

rsync -a will recursively copy subdirectories and also preserve mtime, mode
bits and ownership (if it is being run with sufficient privileges)

It cleverly optimises bandwidth by working out which files or bits of files
already exist, so only copies what is new.

Regards,

Brian.

···

On Sat, May 24, 2003 at 11:55:29PM +0900, kingsley@icecode.org wrote:

How do I copy an entire directory from one place to another?

At the moment I am copying the names of all the sub directories then
creating them in the new location, then recursively going through each
of the sub directories and copying the files to the new directories
created.

This seems like a long way around.

Plus I also want to be able to copy the entire directory to another
machine - I was thinking of opening a socket connection to a listener on
the target machine and trying to copy the files that way.

Any thoughts?

kingsley@icecode.org schrieb im Newsbeitrag
news:20030524150803.22872.qmail@fran.supanetwork.co.uk

Hi

How do I copy an entire directory from one place to another?

At the moment I am copying the names of all the sub directories then
creating them in the new location, then recursively going through each
of the sub directories and copying the files to the new directories
created.

This seems like a long way around.

Plus I also want to be able to copy the entire directory to another
machine - I was thinking of opening a socket connection to a listener on
the target machine and trying to copy the files that way.

Any thoughts?

You can do (all shell level):

local:
cp -a
( cd from && tar cf - . ) | ( cd && tar xf - )

remote
( cd from && tar cf - . ) | ( rsh foo@bar cd ‘&&’ tar xf - )

with GNU tar you can do
( tar cf - -SC . ) | ( rsh foo@bar tar xf - -SC )

and for slow connections even
( tar czf - -SC . ) | ( rsh foo@bar tar xzf - -SC )

You can use ssh instead of rsh, too.

Cheers

robert

“Brian Candler” B.Candler@pobox.com wrote in message
news:20030524164636.GB9502@uk.tiscali.com

For copying to the remote machine, I’d say ‘rsync’ is the best tool. It’s
not a Ruby program or library, but you can run it using system() of
course.
It runs over ssh.

I think Unison is probably a better tool than rsync. It syncs both ways.
Unison uses rsync’s delta algorithm.

http://www.cis.upenn.edu/~bcpierce/unison/

Mikkel