Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: connecting via SSH

by thor (Priest)
on Mar 14, 2006 at 15:53 UTC ( #536610=note: print w/ replies, xml ) Need Help??


in reply to connecting via SSH

In reading the docs for Net::SSH::Perl, it looks like it can take an optional port argument in the new method. Try:

use Net::SSH::Perl; use strict; my $ssh = Net::SSH::Perl->new($host_ssh, port => 22); print "Sto per connettermi al server $host_ssh via ssh\n"; $ssh->login($user_ssh, $passwd_ssh);
and see if that does the trick. It'd be weird if that did it though; you'd think that that would be the default.

thor

The only easy day was yesterday


Comment on Re: connecting via SSH
Download Code
Re^2: connecting via SSH
by nathanvit (Beadle) on Mar 14, 2006 at 16:09 UTC
    I'm really stuck.
    I've declared port as you suggested but when i start my script it responds:
    Your Vendor has not defined Fcntl macro F_SETFL, used at c:/Perl/site/lib/Net/SSH/Perl.pm line 218
    Which "Vendor" does it mean?? I can't understand the meaning...

      Check if you have the module Fcntl. I think it is installed with Perl by default. Btw, are you using Active State or Cygwin's Perl?

      Igor 'izut' Sutton
      your code, your rules.

        Yes, Fcntl is installed by default.
        As a matter of fact if i write into the prompt: perl -e "use Fcntl;" it doesn't give me errors....
        I use Active State distribution...
        Any suggestions?
        Thank you all!

      That error means the OS doesn't support it that flag for fnctl, and that Perl doesn't emulate it. I don't know if that helps, but newer version of Net::SSH::Perl don't use F_SETFL.

      Older version (<= 1.26):

      fcntl($sock, F_SETFL, O_NONBLOCK) or die "Can't set socket non-blocking: $!";

      Newer version (>= 1.27):

      defined($sock->blocking(0)) or die "Can't set socket non-blocking: $!";
      fcntl is not very portable. That's why you get on an OS that support a particular fcntl flag and an fcntl that doesn't emulate it.

      ("Vendor" refers to the OS.)

Re^2: connecting via SSH
by ikegami (Pope) on Mar 14, 2006 at 16:35 UTC

    Normally, the default is accessed by getservbyname, but Windows doesn't have SSH in the "database" accessed by getservbyname. There are three solutions:

    • Specify the port explicitely, as suggested in the parent post.

    • Upgrade to version Net::SSH::Perl version 1.27 or higher. Instead of relying entirely on getservbyname, version 1.27 and higher use 22 (hardcoded) as the port number if getservbyname fails.

      Older version (<= 1.26):

      my @serv = getservbyname(my $serv = $rport, 'tcp'); $rport = $serv[2]; croak "Can't map service name '$serv' to port number" unless defined $rport;

      Newer version (>= 1.27):

      my @serv = getservbyname(my $serv = $rport, 'tcp'); $rport = $serv[2] || 22;
    • Add SSH to the services "database". In windows, it's %SystemRoot%\system32\drivers\etc\services, a text file identical to unix's /etc/services. The entry to add is simply:

      ssh 22/tcp # Secure Shell Login

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536610]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-09-23 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (221 votes), past polls