lkinley / Net-SSH-Perl

Development on the Net::SSH::Perl module to support latest ciphers, key exchange mechanisms, etc.
Other
14 stars 9 forks source link

Could not find a way to prevent Net::SSH::Perl from exiting the script if the detination port has no service. #20

Closed medeiros1 closed 1 year ago

medeiros1 commented 2 years ago

Hi, thanks for this well working module, it does a great job. Unfortunately I could not find a way to prevent the script exiting when the destination port is not under service: If the port is reachable all works fine.

my $remoteport="3302"; my $ssh = Net::SSH::Perl->new($ConfigP::remotehost,options => ["Port $remoteport"]); ^^^^^^^^ exits after the line above, if the port does not provide a service ^^^^^^^^ $ssh->login($ConfigP::remoteuser,$ConfigP::remotepass); my($stdout, $stderr, $exit) = $ssh->cmd("")

Is there a method in the module to check for a port under service instead of exiting ?

Regards Rolf

sensei-hacker commented 2 years ago

You can do:

my $ssh;
eval { $ssh = Net::SSH::Perl->new($ConfigP::remotehost,options => ["Port $remoteport"]) };
warn $@ if $@;
medeiros1 commented 2 years ago

Thanks for the trick ! I didn't realize that eval can be used to prevent a script from exiting when a routine exits. After you wrote it, it became clear to me that it works.

rwp0 commented 2 years ago

I think the newer try/catch syntax can be used here in place of eval as well.

briandfoy commented 1 year ago

I've forked this project at briandfoy/net-ssh-perl, and you can reopen this issue there if you'd like. Otherwise, I'll add it myself at some later time. See #22.

If you include text like transferred from linkley/Net-SSH-Perl#20, GitHub should make a reference between the two issues.

But, I think this issue has been resolved and you can close it.

medeiros1 commented 1 year ago

Thanks, the eval method worked for me as desired.