• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1934
  • Last Modified:

Perl Script to Move Files on a Remote Server

I have a Windows 2000 machine at a customer that I would like to move log/report files older than three days from one folder on it to a cache folder on the same machine.  I want to run a Perl script to do it from a different server running Windows 2008 R2.  The reason I want to run it from a different machine is that I do not have Remote Desktop access to the box, nor does it have Perl installed on it.  I do have full access to the Windows share where my system's files are stored.

I'm a noob relative to Perl, but I was able to move files on the 2008 R2 server when I run the script on it.  Manipulating files on the remote server seems to be the problem.

It seems like it ought to be easy, but I cannot get it to work.  Any insights are appreciated.

use File::Copy;

my $src_dir = '\\\\server_name\\windows_share\\Reports';
my $dst_dir = '\\\\server_name\\windows_share\\Cache\\Reports';

# Move Reports

print "Moving Reports > 3 days old from $src_dir to $dst_dir\n\n";
foreach (<$src_dir\\*.rpt>)
move $_, $dst_dir if -M > 3;

1 Solution
you canuse File::Copy  this is hwo :

use File::Copy;
      copy("file1","file2") or die "Copy failed: $!";
      use File::Copy "cp";
      $n = FileHandle->new("/a/file","r");


OR  NEt::SFTP module

 use Net::SFTP;
    my $sftp = Net::SFTP->new($host);
    $sftp->get("foo", "bar");
    $sftp->put("bar", "baz");

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now