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

Monks
I'm using the expect module to telnet into a remote host and then I want to open and manipulate a file on the remote host.
Here is my code so far.
use strict; use Expect; my $session = new Expect; unless ($session->spawn("telnet $mach_connect")) { print "FATAL: could not connect to $tgt_mach\n"; exit 1; } ... login code here to bring the user to the prompt on the remote host open(FILEHANDLE,"+< $filename"); ... work on the file close(SNMPFILE);
The problem is that the open works on the local system. How do I open and work on the file that is located remotely?

Replies are listed 'Best First'.
Re: How do I open a remote file
by tachyon (Chancellor) on Jul 13, 2004 at 09:12 UTC
Re: How do I open a remote file
by Happy-the-monk (Canon) on Jul 13, 2004 at 09:07 UTC

    The problem is that the open works on the local system. How do I open and work on the file that is located remotely?

    I'd say, the problem is the telnet protocol that doesn't allow you to open a file remotely.

    Chose another way of doing it. Either

    1. Transfer the file to your local working place, read and/or edit, transfer back. SCP, FTP or HTTP might be protocols to chose from.
    2. Use system tools on the remote machine to access the file.
    3. Use Perl on the remote machine to access the file. Problem here is, without accessing a file on the remote machine, you won't be able to save a Perl programme to disk. You could use Perl on the command line there (which works with Telnet) or use methods 1 or 2 to get there... which makes this a bit obsolete though =)

    Cheers, Sören

Re: How do I open a remote file
by ysth (Canon) on Jul 13, 2004 at 09:18 UTC
    Using some other protocol than telnet is much to be preferred, but it is possible to upload/download files with zmodem over a telnet connection.