Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
[stevieb]: The people back then (~2000) are the same people now, but with much more experience. I'm appreciative that I fell into the Perl rabbit hole.
[stevieb]: Coding circles around Python devs, showing how unit tests should be done, enabling easy access to everything, learning basic C to wrap for direct hardware access... I am thankful.
[stevieb]: I'm in an appreciative mood. Thank you fellow Monks, for all I know, and for the knowledge which I can pass on

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2017-02-25 01:26 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (364 votes). Check out past polls.