Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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]
[stevieb]: perldigious: video near our hq in Montreal. Here in Calgary, it's -28c... we've only got 3" of snow so far, but there are several feet in the mountains already
[perldigious]: Snowshoeing time stevieb? I need to buy a pair so I can walk my German Shepherd properly through the country.
[stevieb]: yeah, I snowshoe a fair amount in the mountains. I also use spikes similar to these very often as well
[perldigious]: Discipulus: alternate link
[stevieb]: LOL you can easily replace "Helsinki" with "Alberta"
[perldigious]: I used to live at the top of a very steep hill stevieb, I can relate to the video. Literally used to have to build up momentum and try to force my vehicle to make it up the hill to park in my driveway properly... didn't always make it.
[choroba]: Why don't they use tire chains?
[perldigious]: First snow, probably not prepared right away choroba.

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2016-12-06 16:32 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.