Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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.


The only easy day was yesterday

Replies are listed 'Best First'.
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
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/ line 218
    Which "Vendor" does it mean?? I can't understand the meaning...

      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: $!";

      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!
      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.)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-05-30 06:36 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (171 votes). Check out past polls.