Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 9755

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>ssh2_connect</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Secure Shell2 Functions"
HREF="ref.ssh2.html"><LINK
REL="PREVIOUS"
TITLE="ssh2_auth_pubkey_file"
HREF="function.ssh2-auth-pubkey-file.html"><LINK
REL="NEXT"
TITLE="ssh2_exec"
HREF="function.ssh2-exec.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.ssh2-auth-pubkey-file.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.ssh2-exec.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.ssh2-connect"
></A
>ssh2_connect</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN218814"
></A
><P
>    (PECL)</P
>ssh2_connect&nbsp;--&nbsp;
     Connect to an SSH server
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN218817"
></A
><H2
>Description</H2
>resource <B
CLASS="methodname"
>ssh2_connect</B
> ( string host [, int port [, array methods [, array callbacks]]] )<BR
></BR
><P
>&#13;     Establish a connection to a remote SSH server and return a resource on success, <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on error.
    </P
><P
>&#13;     <CODE
CLASS="parameter"
>methods</CODE
> may be an associative array with up to four parameters
     as described below.
    </P
><P
>&#13;     <DIV
CLASS="table"
><A
NAME="AEN218839"
></A
><P
><B
>表 1. <CODE
CLASS="parameter"
>methods</CODE
> may be an associative array
             with any or all of the following parameters.</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Index</TH
><TH
>Meaning</TH
><TH
>Supported Values*</TH
></TR
></THEAD
><TBODY
><TR
><TD
>kex</TD
><TD
>&#13;          List of key exchange methods to advertise, comma separated
          in order of preference.
         </TD
><TD
>&#13;          <TT
CLASS="literal"
>diffie-hellman-group1-sha1</TT
>,
          <TT
CLASS="literal"
>diffie-hellman-group14-sha1</TT
>, and
          <TT
CLASS="literal"
>diffie-hellman-group-exchange-sha1</TT
>
         </TD
></TR
><TR
><TD
>hostkey</TD
><TD
>&#13;          List of hostkey methods to advertise, come separated
          in order of preference.
         </TD
><TD
>&#13;          <TT
CLASS="literal"
>ssh-rsa</TT
> and
          <TT
CLASS="literal"
>ssh-dss</TT
>
         </TD
></TR
><TR
><TD
>client_to_server</TD
><TD
>&#13;          Associative array containing crypt, compression, and
          message authentication code (MAC) method preferences
          for messages sent from client to server.
         </TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>server_to_client</TD
><TD
>&#13;          Associative array containing crypt, compression, and
          message authentication code (MAC) method preferences
          for messages sent from client to server.
         </TD
><TD
>&nbsp;</TD
></TR
></TBODY
></TABLE
></DIV
>
    </P
><P
>&#13;     * - Supported Values are dependent on methods supported by underlying library.
     See <A
HREF="http://sourceforge.net/projects/libssh2/"
TARGET="_top"
>libssh2</A
> documentation for additional
     information.
    </P
><P
>&#13;     <DIV
CLASS="table"
><A
NAME="AEN218873"
></A
><P
><B
>表 2. 
       <CODE
CLASS="parameter"
>client_to_server</CODE
> and
       <CODE
CLASS="parameter"
>server_to_client</CODE
> may be an associative array
       with any or all of the following parameters.
      </B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Index</TH
><TH
>Meaning</TH
><TH
>Supported Values*</TH
></TR
></THEAD
><TBODY
><TR
><TD
>crypt</TD
><TD
>List of crypto methods to advertise, comma separated
          in order of preference.</TD
><TD
>&#13;          <TT
CLASS="literal"
>rijndael-cbc@lysator.liu.se</TT
>,
          <TT
CLASS="literal"
>aes256-cbc</TT
>,
          <TT
CLASS="literal"
>aes192-cbc</TT
>,
          <TT
CLASS="literal"
>aes128-cbc</TT
>,
          <TT
CLASS="literal"
>3des-cbc</TT
>,
          <TT
CLASS="literal"
>blowfish-cbc</TT
>,
          <TT
CLASS="literal"
>cast128-cbc</TT
>,
          <TT
CLASS="literal"
>arcfour</TT
>, and
          <TT
CLASS="literal"
>none**</TT
>
         </TD
></TR
><TR
><TD
>comp</TD
><TD
>List of compression methods to advertise, comma separated
          in order of preference.</TD
><TD
>&#13;          <TT
CLASS="literal"
>zlib</TT
> and
          <TT
CLASS="literal"
>none</TT
>
         </TD
></TR
><TR
><TD
>mac</TD
><TD
>List of MAC methods to advertise, come separated
          in order of preference.</TD
><TD
>&#13;          <TT
CLASS="literal"
>hmac-sha1</TT
>,
          <TT
CLASS="literal"
>hmac-sha1-96</TT
>,
          <TT
CLASS="literal"
>hmac-ripemd160</TT
>,
          <TT
CLASS="literal"
>hmac-ripemd160@openssh.com</TT
>, and
          <TT
CLASS="literal"
>none**</TT
>
         </TD
></TR
></TBODY
></TABLE
></DIV
>
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Crypt and MAC method "<TT
CLASS="literal"
>none</TT
>": </B
>
      For security reasons, <TT
CLASS="literal"
>none</TT
> is disabled by the underlying
      <A
HREF="http://sourceforge.net/projects/libssh2/"
TARGET="_top"
>libssh2</A
> library unless explicitly enabled
      during build time by using the appropriate ./configure options.  See documentation
      for the underlying library for more information.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <DIV
CLASS="table"
><A
NAME="AEN218919"
></A
><P
><B
>表 3. <CODE
CLASS="parameter"
>callbackss</CODE
> may be an associative array
             with any or all of the following parameters.</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Index</TH
><TH
>Meaning</TH
><TH
>Prototype</TH
></TR
></THEAD
><TBODY
><TR
><TD
>ignore</TD
><TD
>&#13;          Name of function to call when an 
          <TT
CLASS="constant"
><B
>SSH2_MSG_IGNORE</B
></TT
>
          packet is received
         </TD
><TD
>void ignore_cb($message)</TD
></TR
><TR
><TD
>debug</TD
><TD
>&#13;          Name of function to call when an 
          <TT
CLASS="constant"
><B
>SSH2_MSG_DEBUG</B
></TT
>
          packet is received
         </TD
><TD
>void debug_cb($message, $language, $always_display)</TD
></TR
><TR
><TD
>macerror</TD
><TD
>&#13;          Name of function to call when a
          packet is received but the message authentication
          code failed.  If the callback returns <TT
CLASS="constant"
><B
>TRUE</B
></TT
>,
          the mismatch will be ignored, otherwise the
          connection will be terminated.
         </TD
><TD
>bool macerror_cb($packet)</TD
></TR
><TR
><TD
>disconnect</TD
><TD
>&#13;          Name of function to call when an 
          <TT
CLASS="constant"
><B
>SSH2_MSG_DISCONNECT</B
></TT
>
          packet is received
         </TD
><TD
>void disconnect_cb($reason, $message, $language)</TD
></TR
></TBODY
></TABLE
></DIV
>
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN218949"
></A
><P
><B
>例 1. 
      Open a connection forcing 3des-cbc when sending packets,
      any strength aes cipher when receiving packets,
      no compression in either direction,
      and Group1 key exchange.
     </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">/* Notify the user if the server terminates the connection */<br /></font><font color="#007700">function </font><font color="#0000BB">my_ssh_disconnect</font><font color="#007700">(</font><font color="#0000BB">$reason</font><font color="#007700">, </font><font color="#0000BB">$message</font><font color="#007700">, </font><font color="#0000BB">$language</font><font color="#007700">) {<br />&nbsp;&nbsp;</font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"Server disconnected with reason code [%d] and message: %s\n"</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$reason</font><font color="#007700">, </font><font color="#0000BB">$message</font><font color="#007700">);<br />}<br /><br /></font><font color="#0000BB">$methods </font><font color="#007700">= array(<br />&nbsp;&nbsp;</font><font color="#DD0000">'kex' </font><font color="#007700">=&gt; </font><font color="#DD0000">'diffie-hellman-group1-sha1'</font><font color="#007700">,<br />&nbsp;&nbsp;</font><font color="#DD0000">'client_to_server' </font><font color="#007700">=&gt; array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'crypt' </font><font color="#007700">=&gt; </font><font color="#DD0000">'3des-cbc'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'comp' </font><font color="#007700">=&gt; </font><font color="#DD0000">'none'</font><font color="#007700">),<br />&nbsp;&nbsp;</font><font color="#DD0000">'server_to_client' </font><font color="#007700">=&gt; array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'crypt' </font><font color="#007700">=&gt; </font><font color="#DD0000">'aes256-cbc,aes192-cbc,aes128-cbc'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'comp' </font><font color="#007700">=&gt; </font><font color="#DD0000">'none'</font><font color="#007700">));<br /><br /></font><font color="#0000BB">$callbacks </font><font color="#007700">= array(</font><font color="#DD0000">'disconnect' </font><font color="#007700">=&gt; </font><font color="#DD0000">'my_ssh_disconnect'</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$connection </font><font color="#007700">= </font><font color="#0000BB">ssh2_connect</font><font color="#007700">(</font><font color="#DD0000">'shell.example.com'</font><font color="#007700">, </font><font color="#0000BB">22</font><font color="#007700">, </font><font color="#0000BB">$methods</font><font color="#007700">, </font><font color="#0000BB">$callbacks</font><font color="#007700">);<br />if (!</font><font color="#0000BB">$connection</font><font color="#007700">) die(</font><font color="#DD0000">'Connection failed'</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;     Once connected, the client should verify the server's hostkey
     using <A
HREF="function.ssh2-fingerprint.html"
><B
CLASS="function"
>ssh2_fingerprint()</B
></A
>, then authenticate
     using either password or public key.
    </P
><P
>&#13;     See Also:
     <A
HREF="function.ssh2-fingerprint.html"
><B
CLASS="function"
>ssh2_fingerprint()</B
></A
>,
     <A
HREF="function.ssh2-auth-none.html"
><B
CLASS="function"
>ssh2_auth_none()</B
></A
>,
     <A
HREF="function.ssh2-auth-password.html"
><B
CLASS="function"
>ssh2_auth_password()</B
></A
>, and
     <A
HREF="function.ssh2-auth-pubkey-file.html"
><B
CLASS="function"
>ssh2_auth_pubkey_file()</B
></A
>
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.ssh2-auth-pubkey-file.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.ssh2-exec.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ssh2_auth_pubkey_file</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.ssh2.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>ssh2_exec</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>