Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How can I access a file on a remote server?

by Kspoon (Initiate)
on Jan 20, 2003 at 18:42 UTC ( [id://228445]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on How can I access a file on a remote server?

Replies are listed 'Best First'.
Re: How does perl's file I/O work?
by Elian (Parson) on Jan 20, 2003 at 21:04 UTC
    First, try to mount the AIX machine's filesystems (at least the one with this file on it) on your machine. That means either NFS or SAMBA. Then just use it like a local file, and things will work.

    If that's not an option, then you'll probably want to go FTP. use Net::FTP to open an FTP connection to the AIX machine, and query it for the size of the file. (Since it sounds like you're dealing with an ever-changing file) You'll need to hand-parse the data from the FTP directory listings, as there's no standard. If the file's changed, go fetch it and work on the local copy.

    If there's a webserver on the AIX machine, you could consider using LWP instead to fetch the file to the local machine and work on it there.

    If that's not an option either, you'll have to write some sort of widget to run on the remote machine and present the data to your program. This is a fairly straightforward client/server setup, so you can put any protocol you want in place.

    FWIW, with both LWP and Net::FTP, you don't have to have a local copy--you can work with the data as it streams in, but that can be a bit of a pain, so fetching a local copy's probably better.

Re: How does perl's file I/O work?
by Anonymous Monk on Jan 20, 2003 at 21:21 UTC

    Yes, this isn't a so much a *Perl* problem as it is a "How can I access a file on a remote server?" problem.

  • If you can mount the directory, then it would be a trivial solution -- just open the file and process.
  • If there's a webserver running on the AIX box, just write a CGI script that serves up the file. Then, modify the CGI on your PC to pull the file (via LWP::UserAgent) and process as necessary.
  • If not those, then PUNT. Either use FTP or SCP to pull the file onto your PC and process accordingly.
  • Which of these solutions is feasible for your configuration?

    Where do you want *them* to go today?
Re: How does perl's file I/O work?
by artist (Parson) on Jan 20, 2003 at 19:25 UTC

    Welcome to the wonderful world of perl and Perlmonks.org. It is wonderful place and I have enjoyed it. You will find lot of help here and start with reading various sections including Tutorials for Beginners.

    If you just need to print the content of the file:

    open IN, "/path/to/the/file"; while(<IN>){ print; }
    Feel free to ask more describing the exact nature of your problem.

    Artist

      ok I am very sorry for being unclear and also I would really like to thank you all for helping! :) anyways it is telnet enabled. And as a person I would login thru telnet and the file is places in my root directary. IS there anything else I missed? I am sorry.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl and Unix
by Marza (Vicar) on Jan 20, 2003 at 18:59 UTC

    Ahhh start typing?

    What exactly are you trying to do? If this is homework, we like to see some effort put into it. Before asking for help.

    Are you asking for contractors?

    Take a look at the Code Catacombs area. You should find examples on reading files.

Re: How does perl's file I/O work?
by Gilimanjaro (Hermit) on Jan 21, 2003 at 12:03 UTC
    As I understand it, you want to run a script on your workstation, that opens the file on the server and reads/writes it...

    Your available options are determined by the ways the server allows you to connect. The only method I've seen you mention in the thread is by using Telnet, which is definitely not the way to go... Though you could have your client script login thru telnet and have it start another (server)script that allows the two to communicate...

    I recall reading a chapter on RPC (Remote Procedure Call) in O'Reilly's Advanced Perl Programming Book. This method would require you to run a 'homemade' server-script on the server which would allow a client-script to perform any perl command transparantly on the server.

    CPAN's RPC::Simple seems to provide something like this.

    I think the way to go for you though is asking your sysadmin to allow access using NFS or Samba if you're using a windows workstation...

      I will check it out, thanks a lot. Is there any reason why telnet is not a suitable solution? Because I find that Net::Telnet might just do the job, I don't know how to use it yet but it seems like it allows me to make client connections to a TCP port and do network I/O, especially to a port using the TELNET protocol. I don't know if it provides any I/O methods but like, so far I have these code at least these will work for connecting: use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/ksh\$ $/'); $t->open($host); $t->login($username, $passwd); is this correct? What to do after taht I don't know, hopefully I can find out by doing more research, but this seems like it owuld do the job, what do you think? Kelvin
      I will check it out, thanks a lot. Is there any reason why telnet is not a suitable solution? Because I find that Net::Telnet might just do the job, I don't know how to use it yet but it seems like it allows me to make client connections to a TCP port and do network I/O, especially to a port using the TELNET protocol. I don't know if it provides any I/O methods but like, so far I have these code at least these will work for connecting:
      use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/ksh\$ $/'); $t->open($host); $t->login($username, $passwd);
      is this correct? What to do after taht I don't know, hopefully I can find out by doing more research, but this seems like it owuld do the job, what do you think? Kelvin
        Problem is that after establishing the telnet session, the other side of the connection is just a login shell waiting for input. You could use that shell to dump the file and store the input locally, but there is a problem.

        System messages can be sent to a terminal session by the server, which would then show up in the middle of your file. I'm talking about things like 'You have new mail' or 'System will go down for maintenance' and the such.

        If your workstation is a Unix machine, I would suggest buying your sysadmin a pizza and asking him to allow you to connect to your homedir using nfs. If it's a windows machine, do the same after installing an nfs-client for Windows.

        NFS allows you to 'mount' the filesystem on your local machine, making it 'look' local to all your applications. After doing that you could access the file in any way you would want...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found