Perl Script to Move Files on a Remote Server

Posted on 2011-05-03
Last Modified: 2012-05-11
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;

Question by:SeaClay
    1 Comment
    LVL 6

    Accepted 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");

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Normally after a failure of Domain Controller, when promoting new DC the DC is renamed, we will discuss the options in Dcpromo to re-create the DC with the same name. Scenario: You are a small IT shop with two Domain Controllers (Domain Contr…
    I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
    This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
    This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now