Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

how to get telnet output via php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

how to get telnet output via php

Postby expertalert » Tue Apr 23, 2013 12:48 pm

Hi,
I am trying to store all telnet output into an array or a variable, but the code i am using, its giving me only partial result

$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {

echo $contents= stream_get_line($fp, 7024);

}

The telnet output is like this

Trying xx.xx.xx.xx...
Connected to xx.xx.xx.xx.
Escape character is '^]'.
4.0K /xx/ftproot/data1/dirname1
4.0K /xx/ftproot/data1/dirname2
2G /xx/ftproot/data1/dirname3
1G /xx/ftproot/data1/dirname4
..........................................
.............................................
Connection closed by foreign host.

There could be more 300 lines in that output ..

but the php result only giving me partial output .. may be 1/4th of the output ..
how can i store all result in an Array or in a variable ??

the main goal is like this.

if Array has value like dirname4 then do this ...
or Variable has value lik dirname4 then do this ....


Any help will be really appreciate
Thanks
expertalert
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Nov 17, 2012 3:48 am

Re: how to get telnet output via php

Postby johnj » Wed Apr 24, 2013 7:07 am

The second parameter of stream_get_line() is the length of bytes tobe read. Please increase that, or use a while loop and read till the end of the stream.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how to get telnet output via php

Postby expertalert » Wed Apr 24, 2013 7:48 am

Hi
I tryed to use this echo $contents= stream_get_line($fp, 7024);
to

echo $contents= stream_get_line($fp, 12024);

but still its stuck on same place

if i want to do while loop to read untill the end steam how will i use that??
i am stuck on this for a days.. any help will be really help full.
thanks
expertalert
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Nov 17, 2012 3:48 am

Re: how to get telnet output via php

Postby johnj » Thu Apr 25, 2013 7:38 pm

Something like this,
Code: Select all
<?php
while (!feof($handle)) {
    $line = stream_get_line($handle, 1000000, "\n");
}
?>
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron