.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Net::SSH2 3pm" .TH Net::SSH2 3pm "2012-04-25" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::SSH2 \- Support for the SSH 2 protocol via libssh2. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::SSH2; \& \& my $ssh2 = Net::SSH2\->new(); \& \& $ssh2\->connect(\*(Aqexample.com\*(Aq) or die $!; \& \& if ($ssh2\->auth_keyboard(\*(Aqfizban\*(Aq)) { \& my $chan = $ssh2\->channel(); \& $chan\->exec(\*(Aqprogram\*(Aq); \& \& my $sftp = $ssh2\->sftp(); \& my $fh = $sftp\->open(\*(Aq/etc/passwd\*(Aq) or die; \& print $_ while <$fh>; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Net::SSH2\*(C'\fR is a perl interface to the libssh2 () library. It supports the \s-1SSH2\s0 protocol (there is no support for \s-1SSH1\s0) with all of the key exchanges, ciphers, and compression of libssh2. .PP Unless otherwise indicated, methods return a true value on success and false on failure; use the error method to get extended error information. .PP The typical order is to create the \s-1SSH2\s0 object, set up the connection methods you want to use, call connect, authenticate with one of the \f(CW\*(C`auth\*(C'\fR methods, then create channels on the connection to perform commands. .SH "EXPORTS" .IX Header "EXPORTS" Exports the following constant tags: .IP "all" 4 .IX Item "all" All constants. .PP ssh constants: .IP "callback" 4 .IX Item "callback" .PD 0 .IP "channel" 4 .IX Item "channel" .IP "error" 4 .IX Item "error" .IP "socket" 4 .IX Item "socket" .IP "trace" 4 .IX Item "trace" .PD Tracing constants for use with \f(CW\*(C`\->trace\*(C'\fR and \f(CW\*(C`\->new(trace => ...)\*(C'\fR. .IP "hash" 4 .IX Item "hash" Key hash constants. .IP "method" 4 .IX Item "method" .PD 0 .IP "disconnect" 4 .IX Item "disconnect" .PD Disconnect type constants. .PP \&\s-1SFTP\s0 constants: .IP "fx" 4 .IX Item "fx" .PD 0 .IP "fxf" 4 .IX Item "fxf" .IP "sftp" 4 .IX Item "sftp" .PD .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Create new \s-1SSH2\s0 object. .PP To turn on tracing with a debug build of libssh2 use: .PP .Vb 1 \& my $ssh2 = Net::SSH2\->new(trace => \-1); .Ve .SS "banner ( text )" .IX Subsection "banner ( text )" Set the \s-1SSH2\s0 banner text sent to the remote host (prepends required \*(L"\s-1SSH\-2\s0.0\-\*(R"). .SS "version" .IX Subsection "version" In scalar context, returns libssh2 version/patch e.g. 0.18 or \*(L"0.18.0\-20071110\*(R". In list context, returns that version plus the numeric version (major, minor, and patch, each encoded as 8 bits, e.g. 0x001200 for version 0.18) and the default banner text (e.g. \*(L"\s-1SSH\-2\s0.0\-libssh2_0.18.0\-20071110\*(R"). .SS "error" .IX Subsection "error" Returns the last error code; returns false if no error. In list context, returns (code, error name, error string). .SS "sock" .IX Subsection "sock" Returns a reference to the underlying IO::Socket::INET object, or \f(CW\*(C`undef\*(C'\fR if not yet connected. .SS "trace" .IX Subsection "trace" Calls libssh2_trace with supplied bitmask, to enable all tracing use: .PP .Vb 1 \& $ssh2\->trace(\-1); .Ve .PP You need a debug build of libssh2 with tracing support. .SS "method ( type [, values... ] )" .IX Subsection "method ( type [, values... ] )" Sets or returns a method preference; for get, pass in the type only; to set, pass in either a list of values or a comma-separated string. Values can only be queried after the session is connected. .PP The following methods can be set or queried: .IP "\s-1KEX\s0" 4 .IX Item "KEX" Key exchange method names. Supported values: .RS 4 .IP "diffie\-hellman\-group1\-sha1" 4 .IX Item "diffie-hellman-group1-sha1" Diffie-Hellman key exchange with \s-1SHA\-1\s0 as hash, and Oakley Group 2 (see \s-1RFC\s0 2409). .IP "diffie\-hellman\-group14\-sha1" 4 .IX Item "diffie-hellman-group14-sha1" Diffie-Hellman key exchange with \s-1SHA\-1\s0 as hash, and Oakley Group 14 (see \s-1RFC\s0 3526). .IP "diffie\-hellman\-group\-exchange\-sha1" 4 .IX Item "diffie-hellman-group-exchange-sha1" Diffie-Hellman key exchange with \s-1SHA\-1\s0 as hash, using a safe\-prime/generator pair (chosen by server) of arbitrary strength (specified by client) (see \s-1IETF\s0 draft secsh-dh-group-exchange). .RE .RS 4 .RE .IP "\s-1HOSTKEY\s0" 4 .IX Item "HOSTKEY" Public key algorithms. Supported values: .RS 4 .IP "ssh-dss" 4 .IX Item "ssh-dss" Based on the Digital Signature Standard (\s-1FIPS\-186\-2\s0). .IP "ssh-rsa" 4 .IX Item "ssh-rsa" Based on PKCS#1 (\s-1RFC\s0 3447). .RE .RS 4 .RE .IP "\s-1CRYPT_CS\s0" 4 .IX Item "CRYPT_CS" Encryption algorithm from client to server. Supported algorithms: .RS 4 .IP "aes256\-cbc" 4 .IX Item "aes256-cbc" \&\s-1AES\s0 in \s-1CBC\s0 mode, with 256\-bit key. .IP "rijndael\-cbc@lysator.liu.se" 4 .IX Item "rijndael-cbc@lysator.liu.se" Alias for aes256\-cbc. .IP "aes192\-cbc" 4 .IX Item "aes192-cbc" \&\s-1AES\s0 in \s-1CBC\s0 mode, with 192\-bit key. .IP "aes128\-cbc" 4 .IX Item "aes128-cbc" \&\s-1AES\s0 in \s-1CBC\s0 mode, with 128\-bit key. .IP "blowfish-cbc" 4 .IX Item "blowfish-cbc" Blowfish in \s-1CBC\s0 mode. .IP "arcfour" 4 .IX Item "arcfour" \&\s-1ARCFOUR\s0 stream cipher. .IP "cast128\-cbc" 4 .IX Item "cast128-cbc" \&\s-1CAST\-128\s0 in \s-1CBC\s0 mode. .IP "3des\-cbc" 4 .IX Item "3des-cbc" Three-key 3DES in \s-1CBC\s0 mode. .IP "none" 4 .IX Item "none" No encryption. .RE .RS 4 .RE .IP "\s-1CRYPT_SC\s0" 4 .IX Item "CRYPT_SC" Encryption algorithm from server to client. See \s-1CRYPT_CS\s0 for supported algorithms. .IP "\s-1MAC_CS\s0" 4 .IX Item "MAC_CS" Message Authentication Code (\s-1MAC\s0) algorithms from client to server. Supported values: .RS 4 .IP "hmac\-sha1" 4 .IX Item "hmac-sha1" \&\s-1SHA\-1\s0 with 20\-byte digest and key length. .IP "hmac\-sha1\-96" 4 .IX Item "hmac-sha1-96" \&\s-1SHA\-1\s0 with 20\-byte key length and 12\-byte digest length. .IP "hmac\-md5" 4 .IX Item "hmac-md5" \&\s-1MD5\s0 with 16\-byte digest and key length. .IP "hmac\-md5\-96" 4 .IX Item "hmac-md5-96" \&\s-1MD5\s0 with 16\-byte key length and 12\-byte digest length. .IP "hmac\-ripemd160" 4 .IX Item "hmac-ripemd160" \&\s-1RIPEMD\-160\s0 algorithm with 20\-byte digest length. .IP "hmac\-ripemd160@openssh.com" 4 .IX Item "hmac-ripemd160@openssh.com" Alias for hmac\-ripemd160. .IP "none" 4 .IX Item "none" No encryption. .RE .RS 4 .RE .IP "\s-1MAC_SC\s0" 4 .IX Item "MAC_SC" Message Authentication Code (\s-1MAC\s0) algorithms from server to client. See \&\s-1MAC_SC\s0 for supported algorithms. .IP "\s-1COMP_CS\s0" 4 .IX Item "COMP_CS" Compression methods from client to server. Supported values: .RS 4 .IP "zlib" 4 .IX Item "zlib" The \*(L"zlib\*(R" compression method as described in \s-1RFC\s0 1950 and \s-1RFC\s0 1951. .IP "none" 4 .IX Item "none" No compression .RE .RS 4 .RE .IP "\s-1COMP_SC\s0" 4 .IX Item "COMP_SC" Compression methods from server to client. See \s-1COMP_CS\s0 for supported compression methods. .SS "connect ( handle | host [, port [, Timeout => secs ]] )" .IX Subsection "connect ( handle | host [, port [, Timeout => secs ]] )" Accepts a handle over which to conduct the \s-1SSH\s0 2 protocol. The handle may be: .ie n .IP "an ""IO::*"" object" 4 .el .IP "an \f(CWIO::*\fR object" 4 .IX Item "an IO::* object" .PD 0 .IP "a glob reference" 4 .IX Item "a glob reference" .IP "an integer file descriptor" 4 .IX Item "an integer file descriptor" .IP "a host name and port" 4 .IX Item "a host name and port" .PD .SS "disconnect ( [description [, reason [, language]]] )" .IX Subsection "disconnect ( [description [, reason [, language]]] )" Send a clean disconnect message to the remote server. Default values are empty strings for description and language, and \f(CW\*(C`SSH_DISCONNECT_BY_APPLICATION\*(C'\fR for the reason. .SS "hostkey ( hash type )" .IX Subsection "hostkey ( hash type )" Returns a hash of the host key; note that the key is raw data and may contain nulls or control characters. The type may be: .IP "\s-1MD5\s0 (16 bytes)" 4 .IX Item "MD5 (16 bytes)" .PD 0 .IP "\s-1SHA1\s0 (20 bytes)" 4 .IX Item "SHA1 (20 bytes)" .PD .SS "auth_list ( [username] )" .IX Subsection "auth_list ( [username] )" Get a list (or comma-separated string in scalar context) of authentication methods supported by the server; or returns \f(CW\*(C`undef\*(C'\fR. If \f(CW\*(C`undef\*(C'\fR is returned and auth_ok is true, the server accepted an unauthenticated session for the given username. .SS "auth_ok" .IX Subsection "auth_ok" Returns true iff the session is authenticated. .SS "auth_password ( username [, password [, callback ]] )" .IX Subsection "auth_password ( username [, password [, callback ]] )" Authenticate using a password (PasswordAuthentication must be enabled in sshd_config or equivalent for this to work.) .PP If the password has expired, if a callback code reference was given, it's called as \f(CW\*(C`callback($self, $username)\*(C'\fR and should return a password. If no callback is provided, \s-1LIBSSH2_ERROR_PASSWORD_EXPIRED\s0 is returned. .SS "auth_publickey ( username, public key, private key [, password ] )" .IX Subsection "auth_publickey ( username, public key, private key [, password ] )" Note that public key and private key are names of files containing the keys! .PP Authenticate using keys and an optional password. .SS "auth_hostbased ( username, public key, private key, hostname, [, local username [, password ]] )" .IX Subsection "auth_hostbased ( username, public key, private key, hostname, [, local username [, password ]] )" Host-based authentication using an optional password. The local username defaults to be the same as the remote username. .SS "auth_keyboard ( username, password | callback )" .IX Subsection "auth_keyboard ( username, password | callback )" Authenticate using \*(L"keyboard-interactive\*(R". Takes either a password, or a callback code reference which is invoked as \f(CW\*(C`callback\->(self, username, name, instruction, prompt...)\*(C'\fR (where each prompt is a hash with \f(CW\*(C`text\*(C'\fR and \&\f(CW\*(C`echo\*(C'\fR keys, signifying the prompt text and whether the user input should be echoed, respectively) which should return an array of responses. .PP If only a username is provided, the default callback will handle standard interactive responses; Term::ReadKey is required. .SS "auth_agent ( username )" .IX Subsection "auth_agent ( username )" Try to authenticate using ssh-agent. This requires libssh2 version 1.2.3 or later. .SS "auth ( ... )" .IX Subsection "auth ( ... )" This is a general, prioritizing authentication mechanism that can use any of the previous methods. You provide it some parameters and (optionally) a ranked list of methods you want considered (defaults to all). It will remove any unsupported methods or methods for which it doesn't have parameters (e.g. if you don't give it a public key, it can't use publickey or hostkey), and try the rest, returning whichever one succeeded or a false value if they all failed. If a parameter is passed with an undef value, a default value will be supplied if possible. The parameters are: .IP "rank" 4 .IX Item "rank" An optional ranked list of methods to try. The names should be the names of the Net::SSH2 \f(CW\*(C`auth\*(C'\fR methods, e.g. 'keyboard' or 'publickey', with the addition of 'keyboard\-auto' for automated 'keyboard\-interactive'. .IP "username" 4 .IX Item "username" .PD 0 .IP "password" 4 .IX Item "password" .IP "publickey" 4 .IX Item "publickey" .IP "privatekey" 4 .IX Item "privatekey" .PD As in the methods, publickey and privatekey are filenames. .IP "hostname" 4 .IX Item "hostname" .PD 0 .IP "local_username" 4 .IX Item "local_username" .IP "interact" 4 .IX Item "interact" .PD If this is set to a true value, interactive methods will be considered. .IP "cb_keyboard" 4 .IX Item "cb_keyboard" auth_keyboard callback. .IP "cb_password" 4 .IX Item "cb_password" auth_password callback. .SS "channel ( [type, [window size, [packet size]]] )" .IX Subsection "channel ( [type, [window size, [packet size]]] )" Creates and returns a new channel object. The default type is \*(L"session\*(R". See Net::SSH2::Channel. .SS "tcpip ( host, port [, shost, sport ] )" .IX Subsection "tcpip ( host, port [, shost, sport ] )" Creates a \s-1TCP\s0 connection from the remote host to the given host:port, returning a new channel. Binds to shost:sport (default 127.0.0.1:22). .SS "listen ( port [, host [, bound port [, queue size ]]] )" .IX Subsection "listen ( port [, host [, bound port [, queue size ]]] )" Sets up a \s-1TCP\s0 listening port on the remote host. Host defaults to 0.0.0.0; if bound port is provided, it should be a scalar reference in which the bound port is returned. Queue size specifies the maximum number of queued connections allowed before the server refuses new connections. .PP Returns a new Net::SSH2::Listener object. .SS "scp_get ( remote [, local ] )" .IX Subsection "scp_get ( remote [, local ] )" Retrieve a file with scp; local path defaults to basename of remote. \f(CW\*(C`local\*(C'\fR may be an \s-1IO\s0 object (e.g. IO::File, IO::Scalar). .SS "scp_put ( local [, remote ] )" .IX Subsection "scp_put ( local [, remote ] )" Send a file with scp; remote path defaults to same as local. \f(CW\*(C`local\*(C'\fR may be an \s-1IO\s0 object instead of a filename (but it must have a valid stat method). .SS "sftp" .IX Subsection "sftp" Return SecureFTP interface object (see Net::SSH2::SFTP). .SS "public_key" .IX Subsection "public_key" Return public key interface object (see Net::SSH2::PublicKey). .SS "poll ( timeout, arrayref of hashes )" .IX Subsection "poll ( timeout, arrayref of hashes )" Pass in a timeout in milliseconds and an arrayref of hashes with the following keys: .IP "handle" 4 .IX Item "handle" May be a Net::SSH2::Channel or Net::SSH2::Listener object, integer file descriptor, or perl file handle. .IP "events" 4 .IX Item "events" Requested events. Combination of LIBSSH2_POLLFD_* constants (with the \s-1POLL\s0 prefix stripped if present), or an arrayref of the names ('in', 'hup' etc.). .IP "revents" 4 .IX Item "revents" Returned events. Returns a hash with the (lowercased) names of the received events ('in', 'hup', etc.) as keys with true values, and a \f(CW\*(C`value\*(C'\fR key with the integer value. .PP Returns undef on error, or the number of active objects. .SS "block_directions" .IX Subsection "block_directions" Get the blocked direction when a function returns \s-1LIBSSH2_ERROR_EAGAIN\s0, returns \&\s-1LIBSSH2_SOCKET_BLOCK_INBOUND\s0 or \s-1LIBSSH2_SOCKET_BLOCK_OUTBOUND\s0 from the socket export group. .SS "debug ( state )" .IX Subsection "debug ( state )" Class method (affects all Net::SSH2 objects). Pass 1 to enable, 0 to disable. Debug output is sent to stderr via \f(CW\*(C`warn\*(C'\fR. .SS "blocking ( flag )" .IX Subsection "blocking ( flag )" Enable or disable blocking. Note that if blocking is disabled, methods that create channels may fail, e.g. \f(CW\*(C`channel\*(C'\fR, \f(CW\*(C`SFTP\*(C'\fR, \f(CW\*(C`scp_*\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" Net::SSH2::Channel, Net::SSH2::Listener, Net::SSH2::SFTP, Net::SSH2::File, Net::SSH2::Dir. .PP LibSSH2 documentation at . .PP \&\s-1IETF\s0 Secure Shell (secsh) working group at http://www.ietf.org/html.charters/secsh\-charter.html . .PP Net::SSH::Perl. .SH "AUTHOR" .IX Header "AUTHOR" David B. Robins, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2005 \- 2010 by David B. Robins; all rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.