Perl script cant find Net/SSH/Perl.pm - perl

Im trying to run a perl script which involves ssh to a remote server and while executing this code, it throws an error like
Can't locate Net/SSH/Perl.pm in INC <#INC contains:C:/Perl/site/lib c:\perl\lib at line5.
I open ppm graphical UI and installed NET-SSH, area= site
but still not able to execute this script
Here is the script
use strict;
use warnings;
use Net::SSH::Perl;
my $ip=12.14.142.22;
my $user = "qwerty";
my $pass = "termide";
my $ssh = Net::SSH::Perl->new($ip, use_pty => 1);
$ssh->login($user, $pass);

While Foo::Bar often includes a Foo::Bar::Baz module, that isn't the case here.
Net::SSH and Net::SSH::Perl are different distributions. You need to install Net::SSH::Perl.

You should install Net::SSH::Perl, not Net::SSH. The error message is clean about that :)

Net::SSH2 is another SSH client that works on Windows and far easier to install. A PPM is available from here.

Related

Perl - Best way to establish an SFTP connection on windows

I need to put files in a remote directory using SFTP on a Windows machine. I've tried Net::SFTP::Foreign though I can't use it because it needs IO::Pty which is not available on Windows machine. What's the best/simplest way to do this?
Update With Requested Info:
Here are the versions I'm using:
Net::SFTP::Foreign : v 1.89
Net::SSH2 : v 0.69
Net::SFTP::Foreign::Backend::Net_SSH2 : v 0.09
and here is the gist of my code:
$ssh2 = Net::SSH2->new();
$ssh2->connect($host) || die "connect failed";
$ssh2->auth_password($user, $pass) || die "password auth failed";
$sftp = Net::SFTP::Foreign->new(ssh2 => $ssh2,
backend => 'Net_SSH2');
$sftp->error and
die "Unable to stablish SFTP connection: ". $sftp->error;
Right now I'm just trying to establish a connection. I will need to put files on the server. The erro I'm receiving is as follows:
Net::SSH2::timeout(ss, timeout) at C:/Strawberry/perl/site/lib/Net/SSH2.pm line 111, <STDIN> line 1.
The preferred way to use Net::SFTP::Foreign in Windows is probably to use the Net::SFTP::Foreign::Backend::Net_SSH2 backend (update: a Perl module available from CPAN) which uses Net::SSH2 under the hood (which is already included with Strawberry Perl, update: otherwise, you will need to build and install libssh2 yourself which sometimes is not as easy as it should be).
Another option is to tell Net::SFTP::Foreign to use the plink command to run the SSH connection (search for plink on the module docs). Update:plink is part of the PuTTY application distribution, a very popular SSH client that may be already installed in that machine.
Finally you can also try using Net::SSH::Any which provides its own backend for Net::SFTP::Foreign and can run on top of several SSH clients and modules... but it is still in beta!
I have several cross-platform scripts that are using Net::SFTP::Foreign using plink on windows and openssh on linux and it works great. Windows is using the latest strawberry perl release.
my $sftp = Net::SFTP::Foreign->new(
host=> $server,
ssh_cmd => $plink, #Contains full path to plink or path to ssh
user=> $user,
more => ['-i', $keyfile],
stderr_discard => 1,
);
The only thing about using the plink backend is that you have to first manually establish a connection using psftp or Putty gui so it stores the trust confirmation in the registry. After that it is good to go from the script.
The nice thing is you can just have the actual path to ssh or to plink defined in a system level config file and the script just reads what is needed on that particular platform. ie (...\bin\Putty\plink.exe or /usr/bin/ssh )
Not a pure Perl solution, but has been very robust. I don't see IO::Pty on any of my windows boxes so no dependency there for plink.
SFTP is actually SSH with a wrapper to simulate the FTP like commands, so a mdir is actually a ssh 'ls /path/to/dir'.
While there might be a Perl SFTP package that avoids IO::Pty, you might get to your solution much faster by just translating the "FTP" commands into their ssh / scp equivalents and looking at Net::SSH
--- Adding an Example as requested ---
#!/bin/env perl
use Net::OpenSSH ();
my $connection = Net::OpenSSH->new('somehost.com', user => 'myuser', password => 'mypassword' );
my #ls = $connection->capture("ls");
printf "remote listing is %s\n", join(', ', #ls);
This should list the files to your console.
You mentioned not having IO::Pty because it is not available for a windows machine. Perhaps you should be attempting to install IO::Pty::Easy. Note that Net::OpenSSH uses IO::Pty too, but that should be possible to do on windows, provided you also install Glib as indicated in this post http://www.perlmonks.org/bare/?node_id=856863
Good luck!

Can't locate SOAP/Lite.pm in #INC

I am trying to build LDV project by following this instructions, and i know nothing about perl.
i am getting the following error while running the test
ldv-task: NORMAL: Calling LDV-core.
Can't locate SOAP/Lite.pm in #INC (#INC contains: /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/5.10.0/x86_64-linux /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/5.10.0 /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/site_perl/5.10.0/x86_64-linux /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/site_perl/5.10.0 .) at /home/acsia/Desktop/LDV/consol-tools/ldv-core/ldv-core line 7.
BEGIN failed--compilation aborted at /home/acsia/Desktop/LDV/consol-tools/ldv-core/ldv-core line 7.
output of
perlbrew use
is :EDITED:
Currently using perl-5.22.0
output of
locate SOAP/Lite.pm
is
/usr/local/lib/perl5/site_perl/5.22.0/SOAP/Lite.pm
output of
which perl
is
/usr/local/bin/perl
and the LDV-core file is starting like this by default
#!/usr/bin/perl -w
#
my $instrumnet = 'ldv-core';
use FindBin;
# To prevent meaningless module warnings use this instead of use.
BEGIN { $SIG{'__WARN__'} = sub{}; require SOAP::Lite; SOAP::Lite->import(); $SIG{__WARN__}='DEFAULT'; }
use POSIX ":sys_wait_h";
use XML::Twig;
use IO::Socket::INET;
#use File::MimeInfo;
use File::Basename;
use Cwd qw(abs_path);
etc,... etc....
Thanks for your time...
If LDV-Core isn't yours, you should install SOAP::Lite using your system's package manager. If it's yours, read on.
perlbrew plays with your PATH so that executing perl will execute the desired perl.
But your script explicitly uses /usr/bin/perl, so which perl is currently selected using perlbrew switch or perlbrew use is irrelevant.
Stop overriding the default install location, and stop looking where you shouldn't.
unset PERL_MM_OPT
unset PERL_MB_OPT
unset PERL5LIB
unset PERLLIB
echo -ne 'o conf makepl_arg ""\no conf commit\n' | cpan
echo -ne 'o conf mbuildpl_arg ""\no conf commit\n' | cpan
The first four lines only have a temporary effect. You should stop setting those variables in your login script to make the change permanent.
Install SOAP::Lite in the desired Perl.
perlbrew use perl-5.22.0 # Or perl-5.10.0 or whatever
cpan SOAP::Lite
Fix your script's shebang.
perl -i~ -pe'
next if $. != 1;
s/^#!.*//s;
$_ = "#!$^X\n$_";
' LDV-core
PS — You don't need use FindBin;.
perlbrew perl is a way to install many perl versions in same machine. It is like virtenv in python. Perlbrew allow you to switch between various versions of perl and run perl programs against those versions.
system perl means the default version of perl which mostly come with linux distros. perlbrew changes that version against which program needs to run and your program will start running against different version.
If you are making something which does not require a lot of perl versions it is always better to use one version of perl and run programs against them.
Also if you are using linux distros and do not want to get into cpan and how to install perl modules, best is to search for corresponding libraries against that module and install them. For example in your case i search this way
aptitude search soap | grep perl
This give me two libraries on my ubuntu machine of which one is against this module. Installing them is easy and you can focus on your work rather than on how to install cpan modules.

Putty command from Perl

I am trying to run a couple of commands in putty from perl. Right now my code gets me into putty but I am unsure of how to execute commands from there.
my $PUTTY = 'C:\Users\Desktop\putty.exe';
my $dacPutty = "$PUTTY, -ssh username#server - l username -pw password";
system ($dacPutty);
system (ls);
use plink instead. ( http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter7.html )
plink is in the same directory as putty.
Usually in Perl it's better to use a Perl module, where one exists, than to shell out.
Using a module is more portable, and often gives you more control. system introduces many opportunities for security bugs, so it's good to avoid it where possible.
In this case, use Net::SSH::Perl http://search.cpan.org/~turnstep/Net-SSH-Perl-1.38/lib/Net/SSH/Perl.pm
Once installed:
use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new("host1");
$ssh->login("user1", "pass1");
$ssh->cmd("cd /some/dir");
$ssh->cmd("foo");
For reliability, you should actually check the result of each cmd:
my ($stdout, $stderr, $exit) = $ssh->cmd("cd /some/dir");
unless ($exit == 0) {
// Handle failed cd
}
The document notes that with SSH-1, each cmd reconnects, so the above would not work -- you would cd in one shell, then foo in a completely new shell. If you have to use SSH-1, then you'd need to do:
$ssh->cmd("cd /some/dir; foo");
(And you can use a similar trick even if you're making a system call to plink)

BioPerl & CPAN - Problems in installation & error "Can't locate Bio/EnsEMBL/Registry.pm in #INC"

I'm posting this message out of pure desperation, because I really don't know what else to try. I'm a beginner in bioperl and I'm working on a script to parse out some results I got from MolQuest fgenesh. Results are out in .txt format and I want to parse them to GFF and fasta file for mRNA and protein sequences to facilitate comparison with other results we have. So I found the Bio::Tools::Fgenesh module and I'm working on a script with it. Problem is, BioPerl doesn't seem to work on my ubuntu pc
I followed the instructions here http://www.bioperl.org/wiki/Installing_Bioperl_for_Unix . I managed to install CPAN in root mode (otherwise it wouldn't work) and BioPerl via CPAN. All tests were ok, but when I ran this script to test the installation
use strict;
use warnings;
use Getopt::Long;
use Bio::EnsEMBL::Registry;
my $reg = "Bio::EnsEMBL::Registry";
$reg->load_registry_from_db(
-host => "ensembldb.ensembl.org",
-user => "anonymous"
);
my $db_list=$reg->get_all_adaptors();
my #line;
foreach my $db (#$db_list){
#line = split ('=',$db);
print $line[0]."\n";
}
I got the error: "Can't locate Bio/EnsEMBL/Registry.pm in #INC"
I tried to install BioPerl again via Build.PL, running as root, but still came to the same outcome.
Thanks for your help
Merche
You seem to be attempting to use the Ensembl API. This is not part of the BioPerl distribution. Please see http://www.ensembl.org/info/docs/api/api_installation.html for more information about how to install it. We do not recommend you install this in any of the default Perl library location as the API is heavily tied into the data made in the same release. Ensembl provides 4-5 releases per year so maintaining this can be difficult.
Should you have anymore issues then you can contact the developers. We have an active developers mailing list & a helpdesk. See http://www.ensembl.org/info/about/contact/index.html for more information.
I had ecountered the same error as you, working on a windows 64x. Seems Bio::EnsEMBL::Registry is not recognized on my windows computer.
Following all the ENSEMBL-API instructions, I finally came across a debugging page (http://www.ensembl.org/info/docs/api/debug_installation_guide.html). After running C:\src\ensembl/misc-scripts/ping_ensembl.pl, I got again the same error message as listed above.
According to the PERL API help for windows, I need to run "set PERL5LIB=C:\src\bioperl-1.2.3;C:\src\ensembl\modules;C:\src\ensembl-compara\modules;C:\src\ensembl-variation\modules;C:\src\ensembl-funcgen\modules" from the cmd box. Did that, but error remained the same.
Now I included these paths (C:\src\bioperl-1.2.3;C:\src\ensembl\modules;C:\src\ensembl-compara\modules;C:\src\ensembl-variation\modules;C:\src\ensembl-funcgen\modules) directly in my perl script, and this seems to work. Probably this is not the way to do it, but as long as it works, I'm happy.
See an example script (based on excercises provided by Bert Overduin) below:
#!/usr/bin/perl -w
use lib "C:/src/ensembl/modules";
use lib "C:/src/ensembl/modules/Bio/EnsEMBL";
use lib "C:/src/ensembl-compara/modules/Bio/EnsEMBL/Compara";
use lib "C:/src/ensembl-functgenomics/modules/Bio/EnsEMBL/Funcgen";
use lib "C:/src/ensembl-variation/modules/Bio/EnsEMBL/Variation";
use strict;
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous',
-verbose => '1'
);
my $slice_adaptor =
Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "slice" );
get a slice on the entire chromosome X
my $chr_slice = $slice_adaptor->fetch_by_region( 'chromosome', '13', 32_889_000, >32_891_000 );
print "#######################################################\n";
print $chr_slice->seq;
Or alternatively:
#!/usr/bin/perl -w
BEGIN{ push #INC,'C:/src/bioperl-live','C:/src/ensembl/modules','C:/src/ensembl-compara/modules','C:/src/ensembl-variation/modules','C:/src/ensembl-functgenomics/modules';};
use strict;
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous',
-verbose => '1'
);
my $slice_adaptor =
Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "slice" );
get a slice on the entire chromosome X
my $chr_slice = $slice_adaptor->fetch_by_region( 'chromosome', '13', 32_889_000, >32_891_000 );
print "#######################################################\n";
print $chr_slice->seq;

installing Net/SSH/Perl.pm

I am fairly new to scripting with perl. I am trying to ssh into a server and perform some commands. I have to provide a username and password.
When trying to run the script that i have so far (code listed below). I get the following error.
I am assuming this means that i need to install/make Net/SSH/Perl.pm, however, when i follow the instructions and tutorials i have found online, none have worked.
Can someone please assist me. I have tried CPAN and ppm, CPAN says it cannot find net::ssh::perl or other variations of that string. And ppm will not even run, i do not see it in my perl directory. Any help is greatly appreciated!
// The code
#!/usr/bin/perl
use Net::SSH::Perl;
$uName = "username";
$pWord = "password";
$unitIp = $ARGV[0];
my $ssh = Net::SSH::Perl->new($unitIp, 35903);
$ssh->login($uName, $pWord);
my $out = $ssh->cmd("java -version");
print $out;
// the error that is returned
Can't locate Net/SSH/Perl.pm in #INC (#INC contains: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at needsAName.pl line 31.
BEGIN failed--compilation aborted at needsAName.pl line 31.
You can try this:
curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpanm Net::SSH::Perl
case sensitive.
Explanation:
1st line will install "cpanm" - what is IMHO the easiest way installing modules
2nd line will install the module Net::SSH::Perl
Instead of Net::SSH::Perl try using Net::SSH2 or if you are in an Unix/Linux environment Net::OpenSSH. They are far easier to install!
Why should you use Net::OpenSSH instead of other perl ssh? This is what I found after install it via cpanm:
Net::OpenSSH Vs Net::SSH::.* modules
Why should you use Net::OpenSSH instead of any of the other Perl SSH
clients available?
Well, this is the perldoc writters (biased) opinion:
Net::SSH::Perl is not well maintained nowadays (update: a new
maintainer has stepped in so this situation could change!!!), requires
a bunch of modules (some of them very difficult to install) to be
acceptably efficient and has an API that is limited in some ways.
Net::SSH2 is much better than Net::SSH::Perl, but not completely stable
yet. It can be very difficult to install on some specific operative
systems and its API is also limited, in the same way as Net::SSH::Perl.
Using Net::SSH::Expect, in general, is a bad idea. Handling interaction
with a shell via Expect in a generic way just can not be reliably done.
Net::SSH is just a wrapper around any SSH binary commands available on
the machine. It can be very slow as they establish a new SSH connection
for every operation performed.
In comparison, Net::OpenSSH is a pure perl module that doesn't have any
mandatory dependencies (obviously, besides requiring OpenSSH binaries).
just type cpan on terminal and then type: force install Net::SSH::Perl
perl -MCPAN -e 'install Net::SSH::Perl'