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.
Re: Processing Files in a Remote Directory
by salva (Canon) 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.). | [reply] |
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.
| [reply] |
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;
| [reply] [d/l] [select] |
|