http://qs321.pair.com?node_id=608318

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

Dear Monks

Apologies if this is just too basic

I have a bunch of ESX hosts/servers running on Linux OS.

Is there a way where I can connect to a linux host via a win32 box using ActivePerl v5.8?
Blackadder
  • Comment on How can I connect to a Linux Machine from a Windows Box

Replies are listed 'Best First'.
Re: How can I connect to a Linux Machine from a Windows Box
by davidrw (Prior) on Apr 04, 2007 at 16:55 UTC
    short answer: yes.
    long answer: well, _HOW_ do you want to connect and for what purpose? what's (HTTP, FTP, SSH, samba, etc, etc) running on the linux server? The answer to that will determine the perl answer, which will quite possibly be along the lines of LWP/LWP::Simple, Net::FTP, Net::SSH
Re: How can I connect to a Linux Machine from a Windows Box
by syphilis (Archbishop) on Apr 04, 2007 at 17:29 UTC
    Is there a way where I can connect to a linux host via a win32 box using ActivePerl v5.8?

    Yep - at it's most basic, you can run an IO::Socket server script on your linux box, and connect to it via an IO::Socket client script running on the Win32 box. See the "Perl Cookbook" if you have a copy of it. (Actually, at an even more basic level, you could use "Socket" rather than "IO::Socket" scripts.)

    As davorg hinted, if there's an FTP, SSH, HTTP, or Telnet server running, then there are even more options - eg Net::FTP, Net::Telnet, Net::SSH2, Net::SSH::Perl, Net::SSH::W32Perl, or one of the LWP modules.

    Cheers,
    Rob
Re: How can I connect to a Linux Machine from a Windows Box
by ikegami (Patriarch) on Apr 04, 2007 at 17:39 UTC

    You can't force love. Either the machine will connect, or they won't. I wish I could go into further details, but it's a poorly researched field.

    Oh? Not that type of connection? Please specify which type of connection you desire.

      Thanks for the reply so far

      What I am trying to do is to automate the patch upgard/install process on our LINUX servers. The manual process would've been done by logging in (root user and password) to this particular Linux server using a putty session, getting a directory listing, then creating a directory in /temp, copying a .tar file from my local windows PC to this folder, extracting it and then running the setup program...Simple

      However I have started with this 2 codes - for which both didn't work!!
      #! c:/perl/bin/perl.exe use strict; use warnings; use Net::FTP; my $ftp = Net::FTP->new("149.149.149.149", Debug => 0) || die "Cannot +connect $@\n";
      The error i got back was:
      C:\Scripts>ESX_conn2.pl Cannot connect Net::FTP: connect: Unknown error

      and then I tried
      #! c:/perl/bin/perl.exe use strict; use warnings; use IO::Socket; my $Sock = IO::Socket::INET->new('149.149.149.149',80) or die "Cannot +connect $@\n"; $Sock->read(my $data, 1024) until $Sock->atmark;
      I got this error
      C:\Scripts>ESX_conn.pl Cannot connect IO::Socket::INET: Cannot determine remote port
      I would be greatfull for an example code where a connection is made to a Linux machine (either using IP address or host name) from a windows XP box!

      Utmost Regards

      Blackadder
        You say you connect via putty on your XP machine to these Linux machines. Are you sure you have the correct protocol? Are you actually using SSH? If so take a look at Net::SSH, as mention previously in several of the other replies to your first post in this thread?

        Hope this helps

        Martin
        Hello,

        Since you didn't have a Net::Telnet example.... I find that it works well for me. It shouldn't matter if you're on a Windows box or not. As long as the telnetd is running on the Linux machine.
        Of course, I use this in an internal network.
        my $host = "host123"; my $username = "bobjones"; my $password = "mypassword"; my $thost = new Net::Telnet( Timeout => 20, Host => $host, Errmode => "return" ); $thost->login( $username, $password ); my $prompt = "_MYPROMPT_"; $thost->prompt("/$prompt\$/"); $thost->cmd("set prompt = '$prompt'"); # depends on the shell in +use. my $command = "ls"; my @out = $thost->cmd($command); $thost->close;
        getting a directory listing, then creating a directory in /temp, copying a .tar file from my local windows PC to this folder, extracting it and then running the setup program...

        All of the above can be done with Net::Telnet... (I don't know about the copying... I haven't tried that. I usually use Net::FTP for that..)

        Hope it helps...
        regexes


        -------------------------
        Cave ab homine unius libri