Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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.

Comment on Processing Files in a Remote Directory
Re: Processing Files in a Remote Directory
by salva (Monsignor) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://596783]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-11-21 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (114 votes), past polls