$self->set_err(msg=> sprintf("failed to get a prompt from a keyboard interactive message block: %s", ssh_get_error_from_session($self->{ssh_session})));
$self->set_err(msg=> sprintf("failed to set an answer for a question from a keyboard interactive message block: %s", ssh_get_error_from_session($self->{ssh_session})));
library. It doesn't support all the library. It's working in progress.
Right now, you can authenticate and execute commands on a SSH server.
=head1 METHODS
=over 4
=item new
Create new Session object:
my $session = Libssh::Session->new();
=item auth_publickey_auto ([ OPTIONS ])
Tries to automatically authenticate with public key and "none". returns SSH_AUTH_SUCCESS if it succeeds.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<passphrase> - passphrase for the private key (if it's needed. Otherwise don't set the option).
=item auth_list ([ OPTIONS ])
Tries to retrieve a list of accepted authentication methods. Returns a bitfield of the following values:
SSH_AUTH_METHOD_UNKNOWN
SSH_AUTH_METHOD_NONE
SSH_AUTH_METHOD_PASSWORD
SSH_AUTH_METHOD_PUBLICKEY
SSH_AUTH_METHOD_HOSTBASED
SSH_AUTH_METHOD_INTERACTIVE
SSH_AUTH_METHOD_GSSAPI_MIC
The function auth_none() must be called first before the methods are available.
=item auth_password ([ OPTIONS ])
Try to authenticate by password. returns SSH_AUTH_SUCCESS if it succeeds.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<password> - passphrase for the private key (if it's needed. Otherwise don't set the option).
=item auth_kbdint ([ OPTIONS ])
Try to authenticate through the "keyboard-interactive" method. Returns one of the following:
SSH_AUTH_ERROR: A serious error happened\n
SSH_AUTH_DENIED: Authentication failed : use another method\n
SSH_AUTH_PARTIAL: You've been partially authenticated, you still
have to use another method\n
SSH_AUTH_SUCCESS: Authentication success\n
SSH_AUTH_INFO: The server asked some questions. Use
auth_kbdint_getnprmopts() and such to retrieve
and answer them.\n
SSH_AUTH_AGAIN: In nonblocking mode, you've got to call this again
later.
=item auth_kbdint_getname ([ OPTIONS ])
Get the "name" of the message block. Returns undef if there isn't one or it couldn't be retrieved.
=item auth_kbdint_getinstruction ([ OPTIONS ])
Get the "instruction" of the message block. Returns undef if there isn't one or it couldn't be retrieved.
=item auth_kbdint_getnprmopts ([ OPTIONS ])
Get the number of authentication questions given by the server. This function can be used once you've called auth_kbdint() and the server responded with SSH_AUTH_INFO.
=item auth_kbdint_getprompt ([ OPTIONS ])
Get a prompt from a message block. This function can be used once you've called auth_kbdint() and the server responded with SSH_AUTH_INFO to retrieve one of the authentication questions. The total number of quesitons can be retrieved with auth_kbdint_getnprmopts(). Returns a reference to a hash table.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<index> - The number of the prompt you want to retrieve.
The hash table returned has the following attributes:
B<text> - The prompt text.
B<echo> - '0' or '1' bool value whether or not the user's input should be echoed back.
=item auth_kbdint_setanswer ([ OPTIONS ])
Set the answer to a prompt from a message block.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<index> - The number of the prompt you want to give an answer to.
B<answer> - The answer to the question. If reading ipnut from <STDIN> make sure to chomp() and append a "\0" character, otherwise it doesn't seem to work.
=item auth_none ([ OPTIONS ])
Try to authenticate through the "none" method. returns SSH_AUTH_SUCCESS if it succeeds.
=item connect ([ OPTIONS ])
Connect to the ssh server. returns SSH_OK if no error.
By default, the connect does the server check verification.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<connect_only> - Set the value to '1' if you want to do the server check verification yourself.
B<SkipKeyProblem> - Returns SSH_OK even if there is a problem (server known changed or server found other) with the ssh server (set by default. Set '0' to disable).
=item disconnect ()
Disconnect from a session. The session can then be reused to open a new session.
The method take care of the current open channels.
B<Warning>: in many case, you should let the destructor do it!
=item execute_simple ([ OPTIONS ])
Execute a single command. Returns a reference to a hash table.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<cmd> - The command to execute.
B<timeout> - Set the timeout in seconds for the global command execution (By default: 300).
B<timeout_nodata> - Set the timeout in seconds for no data received (By default: 120).
The hash table returned has the following attributes:
B<exit> - SSH_ERROR in case of failure. SSH_AGAIN in case of timeout. SSH_OK otherwise.
B<exit_code> - The exit code of the command executed. undef when timeout.
B<stdout> - The stdout of the executed command.
B<stderr> - The stderr of the executed command.
=item execute ([ OPTIONS ])
Execute multiple commands. If an error occured, please look how to handle it with the callback functions.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<commands> - Reference to an array of hashes.
B<timeout> - Set the timeout in seconds for the global command execution (By default: 300). Each command has its own timeout.
B<timeout_nodata> - Set the timeout in seconds for no data received (By default: 120). Each command has its own timeout.
B<parallel> - Set the number of parallel commands launched (By default: 4).
B<Warning>: Execution times of callbacks count in timeout! Maybe you should save the datas and manages after the execute function.
Look the example above to see how to set the array for B<commands>.
=item error ( )
Returns the last error message. returns undef if no error.
=item get_publickey_hash ([ OPTIONS ])
Get a hash of the public key. If an error occured, undef is returned.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<Type> - Hash type to used. Default: SSH_PUBLICKEY_HASH_SHA1. Can be: SSH_PUBLICKEY_HASH_MD5.
=item get_server_publickey ( )
Returns the server public key. If an error occured, undef is returned.
B<Warning>: should be used if you know what are you doing!
=item options ([ OPTIONS ])
Set options for the ssh session. If an error occured, != SSH_OK is returned.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are:
B<Host> - The hostname or ip address to connect to.
B<User> - The username for authentication.
B<Port> - The port to connect to.
B<Timeout> - Set a timeout for the connection in seconds.
B<LogVerbosity> - Set the session logging verbosity (can be: SSH_LOG_NOLOG, SSH_LOG_RARE,...)
B<SshDir> - Set the ssh directory. The ssh directory is used for files like known_hosts and identity (private and public key). It may include "%s" which will be replaced by the user home directory.
B<KnownHosts> - Set the known hosts file name.
B<Identity> - Set the identity file name (By default identity, id_dsa and id_rsa are checked).
B<RaiseError> - Die if there is an error (By default: 0).
B<PrintError> - print in stdout if there is an error (By default: 0).
=back
=head1 LICENSE
This library is licensed under the Apache License 2.0. Details of this license can be found within the 'LICENSE' text file
=head1 AUTHOR
Quentin Garnier <qgarnier@centreon.com>
=cut
Keyboard Shortcuts
Global
s
Focus search bar
?
Bring up this help dialog
GitHub
gp
Go to pull requests
gi
go to github issues (only if github is preferred repository)