Home · Modules · Classes · Namespaces · Functions

QxtSshClient Class Reference
[QxtNetwork module]

The QxtSshClient class implements a Secure Shell client More...

    #include <QxtSshClient>

Inherits QObject.

Public Types

Public Functions

Signals

Additional Inherited Members


Detailed Description

The QxtSshClient class implements a Secure Shell client

QxtSshClient allows connecting to any standard SSH server.

It provides facilities for password authentication or public key authentication, and provides methods to open a shell or a TCP socket on the remote host.

The passphrase can be set before connecting or it can be provided in response to the authenticationRequired() signal. This allows the password to be stored in advance or prompted for only when needed.

QxtSshClient is based on the third-party library libssh2 (http://www.libssh2.org/) provided under the following license:

    * Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
    * Copyright (c) 2005,2006 Mikhail Gusarov <dottedmag@dottedmag.net>
    * Copyright (c) 2006-2007 The Written Word, Inc.
    * Copyright (c) 2007 Eli Fant <elifantu@mail.ru>
    * Copyright (c) 2009 Daniel Stenberg
    * Copyright (C) 2008, 2009 Simon Josefsson
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms,
    * with or without modification, are permitted provided
    * that the following conditions are met:
    *
    *   Redistributions of source code must retain the above
    *   copyright notice, this list of conditions and the
    *   following disclaimer.
    *
    *   Redistributions in binary form must reproduce the above
    *   copyright notice, this list of conditions and the following
    *   disclaimer in the documentation and/or other materials
    *   provided with the distribution.
    *
    *   Neither the name of the copyright holder nor the names
    *   of any other contributors may be used to endorse or
    *   promote products derived from this software without
    *   specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
    * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
    * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
    * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
    * OF SUCH DAMAGE.

Member Type Documentation

enum QxtSshClient::AuthenticationMethod

ConstantValueDescription
QxtSshClient::PasswordAuthentication0Authenticate using a password
QxtSshClient::PublicKeyAuthentication1Authenticate using a public key

enum QxtSshClient::Error

ConstantValueDescription
QxtSshClient::AuthenticationError0An error occurred while authenticating.
QxtSshClient::HostKeyUnknownError1The host key is unknown.
QxtSshClient::HostKeyInvalidError2The host key is invalid.
QxtSshClient::HostKeyMismatchError3The host key does not match the key recorded in the known hosts.
QxtSshClient::ConnectionRefusedError4The connection was refused.
QxtSshClient::UnexpectedShutdownError5The connection was unexpectedly shut down.
QxtSshClient::HostNotFoundError6The host could not be found.
QxtSshClient::SocketError7An error occurred on the underlying socket.
QxtSshClient::UnknownError8An unknown error occurred.

enum QxtSshClient::KnownHostsFormat

ConstantValueDescription
QxtSshClient::OpenSslFormat0Use the .ssh/known_hosts file format.


Member Function Documentation

QxtSshClient::QxtSshClient ( QObject * parent = 0 )

Constructs a new QxtSshClient with the specified parent.

QxtSshClient::~QxtSshClient ()

Destroys the QxtSshClient object.

bool QxtSshClient::addKnownHost ( const QString & hostname, const QxtSshKey & key )

Adds a host key to the list of known host signatures.

This list is used for host key verification during connection.

See also loadKnownHosts and saveKnownHosts.

void QxtSshClient::authenticationRequired ( QList<QxtSshClient::AuthenticationMethod> availableMethods )   [signal]

void QxtSshClient::connectToHost ( const QString & user, const QString & host, int port = 21 )

Attempts to make a connection to host on the given port as the specified user.

QxtSshClient will attempt to authenticate first using the public key, if provided, then using the password, if provided. If neither of these methods succeed in authenticating, the authenticationRequired() signal will be emitted. The public key and/or password can be changed in a slot directly connected to this signal. After the signal has resolved, the public key and password will be tried again.

The connected() signal will be emitted when the connection is complete. At any point, QxtSshClient can emit error() to signal that an error occurred.

The host parameter can be an IP address or a host name. Host names will be resolved by the server.

void QxtSshClient::connected ()   [signal]

This signal is emitted when a connection to the SSH server has been successfully established.

void QxtSshClient::disconnectFromHost ()

Disconnects the current SSH connection.

Any open channels will be closed. When the connection has been closed, the disconnected() signal will be emitted.

void QxtSshClient::disconnected ()   [signal]

This signal is emitted when the connection to the SSH server has been closed.

void QxtSshClient::error ( QxtSshClient::Error error )   [signal]

This signal is emitted after an error occurs. The error parameter describes the type of error that occurred.

QxtSshKey QxtSshClient::hostKey () const

Returns the host key of the currently connected server.

QString QxtSshClient::hostName () const

Returns the hostname of the currently connected server.

bool QxtSshClient::loadKnownHosts ( const QString & file, KnownHostsFormat c = OpenSslFormat )

Loads a list of known host signatures from a file.

This list is used for host key verification during connection.

QxtSshProcess * QxtSshClient::openProcessChannel ()

Opens a new SSH channel that can invoke a process or SSH subsystem on the SSH server. The process's stdin, stdout, and stderr are piped through the channel.

Returns NULL if an error occurs while opening the channel, such as not being connected to an SSH server.

See also QxtSshProcess.

QxtSshTcpSocket * QxtSshClient::openTcpSocket ( const QString & hostName, quint16 port )

Opens a new SSH channel and attempts to establish a TCP connection from the SSH server to a remote host. Traffic on this TCP connection is tunneled through the channel.

Note that traffic between the SSH server and the remote host is unencrypted. Only communication between QxtSshClient and the SSH server is encrypted.

Returns NULL if an error occurs while opening the channel, such as not being connected to an SSH server.

See also QxtSshTcpSocket.

bool QxtSshClient::saveKnownHosts ( const QString & file, KnownHostsFormat c = OpenSslFormat ) const

Saves the current list of known host signatures to a file.

See also loadKnownHosts.

void QxtSshClient::setKeyFiles ( const QString & publicKey, const QString & privateKey )

Sets a public and private key pair to use to authenticate to the SSH server.

If the private key is secured with a passphrase, the passphrase set with setPassphrase() will be used.

void QxtSshClient::setPassphrase ( const QString & pass )

Sets the password for the user. This password is also used for the passphrase of the private key.


Copyright © 2007-2010 Qxt Foundation
Qxt 0.7.0