doowah2004 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have data that I am asked to move from one network drive to another with enough regularity for me to want to give this ability to those who are asking. The problem is that the data is extremely sensitive, and those that need it are not very computer literate. I decide to write a little gui app that would allow them to move the data only (no delete, no over-write). Everything is done, and works except the actual transfer. Here are the params:

1. Network folders i.e. \\computername\folder 1\datafolder
2. I need to copy the datafolder and all info in it.
3. I do not want to map the drives


I am able to read all of the directories in the appropriate network location using readdir(), but when I try to copy using File::NCopy I get the error: No Such File or Directory

Here is the syntax that I am using:
$folder1 = "\\\\computername\\folder 1"; $folder2 = "\\\\diffcomputer\\other folder"; $data = "datafolder"; if (copy \1,"$folder1\\$data","$folder2\\$data"){} else {die "did not +copy: $!";}


Obviously this is not my exact code, but it is the format. Can some one point me in the right direction?

Once again, thanks in advance,

Cameron
  • Comment on Difficulties in copying directories from one network drive to another.
  • Download Code

Replies are listed 'Best First'.
Re: Difficulties in copying directories from one network drive to another.
by waswas-fng (Curate) on Sep 16, 2004 at 19:58 UTC
    The problem is that the data is extremely sensitive, and those that need it are not very computer literate.

    Then by all means don't use CIFS to transfer it. Set up an automated time based scp/sftp or other encrypted file transfer to the server.


    -Waswas
Re: Difficulties in copying directories from one network drive to another.
by nimdokk (Vicar) on Sep 16, 2004 at 19:58 UTC
    My suggestion would be to use File::Copy and File::Spec.

    use File::Spec; use File::Copy; $folder1=File::Spec->catdir('//computerA','share','folder'); $folder2=File::Spec->catdir('//diffcomputer','share','new folder'); copy "$folder1/file.txt", "$folder2/new_file.txt" or die "Cannot copy +file.txt from $folder1 to $folder2. $!";

    In that snippet, note the direction of the slashes for the computer name. It might seem backwards but it works. Also, using single quotes instead of double quotes means that the slashes won't get interpolated. And this does work, we do it all the time, every day in fact. All our scripts use UNC or absolute pathnames (Windows or Unix). What you may be running into is a problem with the space in the "other folder" name. Just a hunch, it causes us problems with some things unless we specially wrap double quotes around it to get it to work right. Hope that helps.

    update: My mistake, I misread. I thought you were talking about files, not directories.

      I gave it a try...still no go. I then tried to copy a file with it and not a directory...no good either. If I use:
      sub copyFile { my $source=shift(@_); my $dest=shift(@_); my $moo=1; open(FA,$source); open(F,">$dest"); binmode(F); binmode(FA); while(($moo=read(FA,$buff,4096))>0){ print F $buff; } close(FA);close(F); }

      Taken from CopyDocs, I can copy a file no prob from one network computer to the other. But I need to transfer a directory. Hmmm...I may have to breakdown and write a subroutine that uses the above recursively and create the directories.

      Cameron
Re: Difficulties in copying directories from one network drive to another.
by husker (Chaplain) on Sep 16, 2004 at 21:01 UTC
    I suggest you look at using the Robocopy utility that comes with with the Windows 2000 Server Resource Kit. (there's apparently an XP and .Net version linked from that same page). It does robust filecopy, can sync directories, preserve security settings, can use UNC notation instead of mapped drives, can do retries, etc.

    Use your GUI to get the right parameters for Robocopy, then parse Robocopy's output to summarize for the user what was done, etc. Robocopy could even make records in an administrative log for your monitoring needs.

      Robocopy worked great. Thanks for the pointer.

      Cameron
Re: Difficulties in copying directories from one network drive to another.
by bibliophile (Prior) on Sep 16, 2004 at 19:26 UTC
      Thanks, but unfortunately I am using the absolute path (though I did verify this with Win32-AbsPath-1.0), and libwin32 would allow me to move a directory (unverified), but not copy it.

      I will keep plugging away,

      Cameron
        Let us know how it works out...

        :-)