Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Processing Files in a Remote Directory

by flooseman (Initiate)
on Jan 26, 2007 at 20:17 UTC ( #596783=perlquestion: print w/replies, xml ) Need Help??
flooseman has asked for the wisdom of the Perl Monks concerning the following question:

Revered Monks, I am a newcomer to Perl and have been tasked with the job of developing a script that will process all files in a directory located on a remote server. I have succeeded in writing a script that will process the contents of a local directory but now I need to add code so it will do the same thing for a remote directory. I was looking at File::Remote (found it in CPAN), but it appears that this will not let me open a remote directory and process every file in it. It seems to be limited to working with a remote file and not a directory. I need to do a remote equivalent of opendir, readdir and closedir; for each member in the directory list, I need to do the usual open, read and close. Can this be done entirely from within Perl or will I need to FTP the directory contents to a local folder from which I can then run my Perl script? Your input is greatly appreciated.

Replies are listed 'Best First'.
Re: Processing Files in a Remote Directory
by salva (Abbot) on Jan 26, 2007 at 20:51 UTC
    If SFTP access to the remote machine is available, Net::SFTP::Foreign has methods that mimic most Perl directory and file handling built-in functions (opendir, readdir, open, close, read, write, readline, seek, stat, etc.).
Re: Processing Files in a Remote Directory
by ptum (Priest) on Jan 27, 2007 at 00:25 UTC

    Another way to skin that cat is to build a small client application that runs on the remote system (if you are permitted to install something there) and then you simply invoke it from your script (maybe via Net::SSH), letting it do the processing remotely and then reporting back with its success/failure.

Re: Processing Files in a Remote Directory
by f00li5h (Chaplain) on Jan 27, 2007 at 01:02 UTC

    Depending on how remote the server, perhaps you can just mount the remote directory locally and then process the files from within the mount point.

    or perhaps you can rsync(1) a local directory with the one found on the remote hostt.

    Ofcourse these both assumes a good quick link to the remove host, the ability to export filesystems, and perhaps even some sort of unix-like, and may be limited by access to the database you may be maintaining state in.

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://596783]
Approved by Corion
[Corion]: Hmm - I would say the 5.8.5 is a broken installation / corrupt tarball download, and the 5.10.0 is really weird, and maybe a bug in that version of Perl
[Corion]: I don't see how my $result = eval q{'abc' =~ ?b?}; could create a "Modification of read-only value" error
[marto]: Discipulus the issue that should be adressed is that the page needs to be updated to reflect modern perl on Windows
[Discipulus]: but is really necessary to support these ancient versions? from 5.14 onward is not enough?
[Discipulus]: yes marto I understood
[Corion]: Discipulus: I'm slowly migrating my code to require 5.8.x ;) Most of my code works on 5.6, but Filter::signatures requires 5.10 I think
[Corion]: 5.14 is also a good target, widely available and fairly stable. Also, over five years old, which doesn't push people into a needless upgrade cycle
[Discipulus]: yes I saw your efforts Corion but the pain is worth?
[Corion]: Discipulus: IMO it's not that much pain, but most of the systems I use have a Perl 5.14 or newer on them nowadays

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2018-06-25 08:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.