in reply to Copy file from Windows server to antoher windows server

Couple of things:

1) File::Spec (makes using path info easier).

2) File::Copy (use Perl copy rather than making a system call.

3) To send a file to Unix, you might want to look at something like Net::FTP and use FTP to transfer the file from one platform to the other.

  • Comment on Re: Copy file from Windows server to antoher windows server

Replies are listed 'Best First'.
Re^2: Copy file from Windows server to antoher windows server
by Anonymous Monk on May 03, 2006 at 18:26 UTC
    Thanks, What the difference between File::Copy and using system copy command? Does the File::Copy use less server processing?
      • File::Copy's copy puts a lot effort in being portable.
      • It's well tested.
      • It doesn't launch a seperate process, so it's faster and uses less memory. Instead, it uses a system call (or Perl code if the OS doesn't have such a call).
      • It can copy from/to file handles instead of just from/to files.
      • Its arguments are not subject to shell interpretation. (The way in which you used system is buggy and unsafe.)
      • It's makes checking for success much easier.
      • It provides meaningful error messages in $!, on most systems.

      On the other hand,

      • Your expression is not portable.
      • It's not well tested. In fact, there are bugs.
      • It launchs *two* seperate processes, so it's slower and uses more memory.
      • It can't copy from/to file handles, just from/to files.
      • Its arguments are subject to shell interpretation (although that can be fixed). The way in which you used system is buggy and unsafe. (Bug 1)
      • It thinks it succeeds even if the copy fails, as long as the shell was successfully loaded. (I think.) (Bug 2)
      • $! does not contain what you think it does here. It definitely does not contain why the copy failed when it does. (Bug 3)
      For one thing, you don't have to spawn (I think that's the right term) a second process if you use Perl's copy instead of the system command. Also, I find it easier to verify that your copy in fact worked correctly (though this can be done with a system call as well I'm sure).