Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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

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/Perl.pm 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536610]
help
Chatterbox?
[Tux]: choroba++ # pm_cb_g also signals replies to posts, something#cbstream does not
[marto]: good afternoon all
[marto]: that is a neat feature, I'll have to have a look at how it displays that
[Tux]: 14:32 Europe/Amsterdam, so good afternoon to you :)
[marto]: 13:32, sunny Glasgow :P
[Tux]: as in, some others might appreciate a good morning or goor evening
[Tux]: Glasgow, as in TPCiG-2018 !!!! :) :)
erix would rather appreciate proof of a goodmorning
[marto]: Tux so I'm told :)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2017-09-22 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (263 votes). Check out past polls.

    Notices?