CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
How to use telnet via ssh?


New User

Oct 18, 2004, 8:37 AM

Post #1 of 1 (1327 views)
How to use telnet via ssh? Can't Post

I use ssh first to login a device, then need use telnet to login the other one from the ssh. when I try it, always get the msg:
"fhopen filehandle cannot be opened".
any idea on it? Thanks

use Net::SSH::Perl;

print "Logging in,...\n";

$host = "";
print $host;

my $ssh = Net::SSH::Perl->new($host,protocol => 2 );

$ssh->login("usr", "passwd");


my($myip,$b,$c) = $ssh->cmd("telnet $ip2");
if ($c != 0) {
#die "cannot telnet\n";
print "telnet $ip2";

use Net::Telnet;
my $t= new Net::Telnet (
-fhopen => $myip,
-prompt => $prompt,
-telnetmode => 0,
-cmd_remove_mode => 5,
-output_record_separator => "\r");

## Login to remote host.
$t->waitfor(-match => '/password: ?$/i',
-errmode => "return")
or die "problem connecting to host: ", $t->lastline;
$t->waitfor(-match => $t->prompt,
-errmode => "return")
or die "login failed: ", $t->lastline;

## Send command, get and print its output.
@lines = $t->cmd("ls");
print @lines;



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives