hotshot has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys!
Can I open a file for writing on another computer using the open function? for example:
I have several computers connected to each other that can be accessed by rsh from the Linux prompt. I have a main computer which runs a perl script and would like to edit a file on each of these computers from the main one (the files are not the same on each computer so I can't just edit the local one and distribute it via rcp).
Thanks

Hotshot

Replies are listed 'Best First'.
Re: Opening a file for writing
by Jenda (Abbot) on Oct 03, 2002 at 10:36 UTC

    Unless the disks on the other computers are mounted by NFS or something you can't open the files directly. But if you can copy them around with rcp, you can fetch the file from a computer to a temp directory, change it and copy it back.

    Jenda

Re: Opening a file for writing
by fsn (Friar) on Oct 03, 2002 at 11:20 UTC
    It would be cool if you could open an ftp or an scp session like a filehandle, but unfortunately you can't. The underlying functionality, like scp, doesn't seem to support reading or writing to anything else than a file on disc. If it could at least read and write from STDIN/STDOUT, you could possibly wrap an scp session in a module that would allow accessing it as a filehandle. If you wanted to implement that today, you would have to change the scp binary.

    Anyway, look at the scp modules, they seem to be really nice when it comes to transfering files back and forth.

    You aren't using rcp are you? scp is almost a drop-in replacement, and apart from the increased security, it's in my opinion more robust. ssh really gives you so many added features over rsh/rcp/xrsh...

Re: Opening a file for writing
by robartes (Priest) on Oct 03, 2002 at 12:44 UTC
    somewhat in the vain of fglock's reply above:

    If you have ftp access to the machines, you could use ftpfs to mount the remote system locally and then you can access its files using normal open/read/write calls, as you want.

    Another, seriously more involved, solution is to use netcat (google around for it). You'd want to put netcat on both sides of the connection, connect the target file to the remote netcat and then use socket calls to open a filehandle on the local netcat, through which you can access the remote file. This solution is a lot more complicated and error-prone than the first one, but should work even if you do not have ftp access or root access to the other machine.

    CU
    Robartes-

Re: Opening a file for writing
by fglock (Vicar) on Oct 03, 2002 at 12:17 UTC

    Can I open a file for writing on another computer using the open function?

    You could if you had lufs