Hello,
I wish to establish a connection in language PHP on a UNIX server by telnet.
In fact, I would like :
- Connect to server by sending IP adress, login, password
- Send an order (example: LS - Al)
- Receive the result in a string
- Send an order (example: CD ..)
- Receive the result in a string
- Etc...
I am already at a advanced stage but I am not solved my problem completely.
I have actually 3 solutions:
Solution 1:
-----------
A program write with the sockets
//Function reading the flow
function lisflux($flux)
{
// waiting the first char
$Char = false;
while (!$Char) $Char = fgetc($flux);
$Output = $Char;
//Reading next chars
$Output. = fread($flux, 1024);
//Replace the carriage return
$Output = str_replace("\n ", " ", $Output);
return $Output;
}
$Socket = pfsockopen($Hos tName, $Port);
if (! $Socket)
{
echo 'Connetion refused : <br>';
echo strerror ($Socket) . '<br>';
}
else
{
// Header 1
fputs($Socket, $Header1);
lisflux($Socket );
//Header 2
fputs($Socket, $Header2);
echo lisflux($Socket );
//Writing the login
fputs($Socket, "login\r");
echo lisflux($Socket );
//Writing Passwd
fputs($Socket, "passwd\r") ;
echo lisflux($Socket );
//Writing the order
fputs($Socket, #Commande. "\r");
echo lisflux($Socket );
}
This solution works correctly but it not stable
- I can't modify the timeout which remains hopelessly fixed to 30s
- The returned flow is sometimes incorrect.
In fact, I make 2 times the same thing but I do not obtaint the same
result.
Sometimes, returned flow is truncated. Sometimes, it is correct.
Is somebody already wrote a functional program in PHP with the sockets for
telnet?
Solution 2:
-----------
Use CURL which is originally implemented in PHP.
I wrote a program in PHP with CURL library.
This program runs correctly for a connection HTTP, ftp...
On the other hand, I have no documentation and no example for a connection
telnet
Is somebody already wrote a functional program in PHP with the CURL library
?
Solution 3:
-----------
Use EXPECT library
I have downloaded EXPECT for Windows (I develop with EasyPHP)
But the documentation is completely incompéhensible
Is somebody already wrote a functional program in PHP with the EXPECT
library ?
Thank you by advance to answer on my email: rp*******@buyin gpack.com
Robert PADOVANO