3 "Robert PADOVANO" wrote in message news:40893851$0$27025$626a14ce@news.free.fr...[quote] > Hello, > > I wish to establish a connection in language PHP on a UNIX server by[/quote] telnet.[quote] > 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[/quote] completely.[quote] > 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($HostName, $Port); > > if (! $Socket) > { > echo 'Connetion refused :
'; > echo strerror ($Socket) . '
'; > } > 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[/quote] library[quote] > ? > > > > 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: [email]rpadovano@buyingpack.com[/email] > > Robert PADOVANO > > > > >[/quote] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <40893851$0$27025$626a14ce@news.free.fr> [htmlstate] => on_nl2br [postusername] => Cerbain [ip] => cerbain@cerbain [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> Establish a connection telnet in PHP on a UNIX server - PHP Development

Establish a connection telnet in PHP on a UNIX server - PHP Development

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) { // ...

  1. #1

    Default Establish a connection telnet in PHP on a UNIX server

    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($HostName, $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 doentation 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 doentation 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: [email]rpadovanobuyingpack.com[/email]

    Robert PADOVANO





    Robert PADOVANO Guest

  2. #2

    Default Re: Establish a connection telnet in PHP on a UNIX server

    Robert PADOVANO spilled the following:

    <snip>
    > This solution works correctly but it not stable
    It's a long way short of a telnet client implementation (see rfc 854).
    I wouldn't bother myself.
    >
    > Is somebody already wrote a functional program in PHP with the CURL
    > library ?
    >
    Yes but not for telnet - Curl doesn't (AFAIK do telnet)
    > Use EXPECT library
    > I have downloaded EXPECT for Windows (I develop with EasyPHP)
    > But the doentation is completely incompéhensible
    >
    There are other resources out there - expect was written to do exactly this
    kind of thing - but wouldn't be my prefered solution.

    To solve the problem I'd either....

    1) write both ends of a client/server program. Although seemingly rather
    trivial it would get terribly complicated when you start trying to deal
    with privilege seperation.

    2) use ssh - I'm not sure if putty (excellent MSWindows ssh client) supports
    command line commands which are possible with a conventional ssh client
    e.g.
    ssh userremotehost 'ls -l /home/user/public_html'
    would connect to remotehost as user, if a key pair was setup, would log in -
    otherwise prompting for a password, then run the command 'ls -l
    /home/user/public_html' then disconnect. With most ssh implementations, the
    first time you connect to a remote system is prompts you to accept the
    hosts key - but after that it should be recognised automatially. You also
    don't have the problem of cleartext passwords as with telnet.

    HTH

    C.
    Colin McKinnon Guest

  3. #3

    Default Re: Establish a connection telnet in PHP on a UNIX server

    Hi Robert,

    I solved some of your problems in this app:
    [url]http://www.cerbain.net/phptelnetclient/[/url]

    The client gives you an interactive way to talk to telnet hosts. I use it to
    connect to talkers & muds etc. I overcame the timeout problem by resetting
    the timeout counter. Although the app is able to send and recieve plain text
    it does not interprete telnet control at all. If you want to more special
    chars etc come out correctly, perhaps have a look at
    [url]http://pear.php.net/packages.php?catpid=5&catname=Console[/url].

    BTW, The demo does not work on my server because my hostingprovider decided
    to close the outbound telnet port. I am curious in your progress.

    Cerbain

    e-mail address = 1st e -->3

    "Robert PADOVANO" <rpadovanobuyingpack.com> wrote in message
    news:40893851$0$27025$626a14cenews.free.fr...
    > 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($HostName, $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 doentation 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 doentation 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: [email]rpadovanobuyingpack.com[/email]
    >
    > Robert PADOVANO
    >
    >
    >
    >
    >

    Cerbain Guest

Similar Threads

  1. Replies: 5
    Last Post: January 7th, 04:36 AM
  2. Timed out trying to establish connection
    By ladybug in forum Coldfusion Database Access
    Replies: 21
    Last Post: October 5th, 09:01 PM
  3. Replies: 4
    Last Post: September 22nd, 01:05 PM
  4. Permanent connection between a LINUX server and a UNIX AIX server
    By Robert PADOVANO in forum Linux / Unix Administration
    Replies: 1
    Last Post: April 23rd, 01:34 PM
  5. Client unable to establish connection
    By Jen in forum ASP Database
    Replies: 5
    Last Post: November 3rd, 08:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •