📄 function.ssh2-connect.html
字号:
<i>aes128-cbc</i>, <i>3des-cbc</i>, <i>blowfish-cbc</i>, <i>cast128-cbc</i>, <i>arcfour</i>, and <i>none**</i> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">comp</td> <td colspan="1" rowspan="1" align="left">List of compression methods to advertise, comma separated in order of preference.</td> <td colspan="1" rowspan="1" align="left"> <i>zlib</i> and <i>none</i> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">mac</td> <td colspan="1" rowspan="1" align="left">List of MAC methods to advertise, come separated in order of preference.</td> <td colspan="1" rowspan="1" align="left"> <i>hmac-sha1</i>, <i>hmac-sha1-96</i>, <i>hmac-ripemd160</i>, <i>hmac-ripemd160@openssh.com</i>, and <i>none**</i> </td> </tr> </tbody> </colgroup> </table> </p> <p class="para"> <blockquote><p><b class="note">Note</b>: <b>Crypt and MAC method "<i>none</i>"</b><br /> For security reasons, <i>none</i> is disabled by the underlying <a href="http://sourceforge.net/projects/libssh2/" class="link external">» libssh2</a> library unless explicitly enabled during build time by using the appropriate ./configure options. See documentation for the underlying library for more information. <br /> </p></blockquote> </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">callbacks</tt></i></span> <dd> <p class="para"> <i><tt class="parameter">callbacks</tt></i> may be an associative array with any or all of the following parameters. <table border="5"> <caption><b> Callbacks parameters </b></caption> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Index</th> <th colspan="1">Meaning</th> <th colspan="1">Prototype</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">ignore</td> <td colspan="1" rowspan="1" align="left"> Name of function to call when an <b><tt>SSH2_MSG_IGNORE</tt></b> packet is received </td> <td colspan="1" rowspan="1" align="left">void ignore_cb($message)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">debug</td> <td colspan="1" rowspan="1" align="left"> Name of function to call when an <b><tt>SSH2_MSG_DEBUG</tt></b> packet is received </td> <td colspan="1" rowspan="1" align="left">void debug_cb($message, $language, $always_display)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">macerror</td> <td colspan="1" rowspan="1" align="left"> Name of function to call when a packet is received but the message authentication code failed. If the callback returns <b><tt>TRUE</tt></b>, the mismatch will be ignored, otherwise the connection will be terminated. </td> <td colspan="1" rowspan="1" align="left">bool macerror_cb($packet)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">disconnect</td> <td colspan="1" rowspan="1" align="left"> Name of function to call when an <b><tt>SSH2_MSG_DISCONNECT</tt></b> packet is received </td> <td colspan="1" rowspan="1" align="left">void disconnect_cb($reason, $message, $language)</td> </tr> </tbody> </colgroup> </table> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a resource on success, or <b><tt>FALSE</tt></b> on error. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>ssh2_connect()</b> example</b></p> <div class="example-contents"><p> 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. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Notify the user if the server terminates the connection */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_ssh_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$reason</span><span style="color: #007700">, </span><span style="color: #0000BB">$message</span><span style="color: #007700">, </span><span style="color: #0000BB">$language</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Server disconnected with reason code [%d] and message: %s\n"</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">$reason</span><span style="color: #007700">, </span><span style="color: #0000BB">$message</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$methods </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'kex' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'diffie-hellman-group1-sha1'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'client_to_server' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'crypt' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'3des-cbc'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'comp' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'none'</span><span style="color: #007700">),<br /> </span><span style="color: #DD0000">'server_to_client' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'crypt' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'aes256-cbc,aes192-cbc,aes128-cbc'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'comp' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'none'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$callbacks </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'disconnect' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'my_ssh_disconnect'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">ssh2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'shell.example.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">22</span><span style="color: #007700">, </span><span style="color: #0000BB">$methods</span><span style="color: #007700">, </span><span style="color: #0000BB">$callbacks</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$connection</span><span style="color: #007700">) die(</span><span style="color: #DD0000">'Connection failed'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.ssh2-fingerprint.html" class="function" rel="rdfs-seeAlso">ssh2_fingerprint()</a></li> <li class="member"><a href="function.ssh2-auth-none.html" class="function" rel="rdfs-seeAlso">ssh2_auth_none()</a></li> <li class="member"><a href="function.ssh2-auth-password.html" class="function" rel="rdfs-seeAlso">ssh2_auth_password()</a></li> <li class="member"><a href="function.ssh2-auth-pubkey-file.html" class="function" rel="rdfs-seeAlso">ssh2_auth_pubkey_file()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.ssh2-auth-pubkey-file.html">ssh2_auth_pubkey_file</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ssh2-exec.html">ssh2_exec</a></div> <div class="up"><a href="ref.ssh2.html">SSH2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -