libssh2 API reference


Table of Contents

1. Session operations
libssh2_session_init_ex - initialize a libssh2 session handle
libssh2_banner_set - set the SSH prococol banner for the local client
libssh2_session_method_pref - set preferred key exchange method
libssh2_session_methods - return the currently active algorithms
libssh2_session_callback_set - set a callback function
libssh2_session_startup - start ssh2 on a socket
libssh2_session_disconnect_ex - disconnect a session
libssh2_session_abstract - return a pointer to a session's abstract pointer
libssh2_session_free - close all channels in a session, and free all associated memory
libssh2_session_last_error - return the last error code
2. Authentication
libssh2_hostkey_hash - return a hash of the remote host's key
libssh2_userauth_password_ex - authenticate a session with username and password
libssh2_userauth_publickey_fromfile - authenticate a session with a public key, read from a file
libssh2_userauth_list - list the authentication methods supported by a server
libssh2_userauth_authenticated - return authentication status
3. Channel operations
libssh2_channel_open_ex - establish a generic session channel
libssh2_channel_setenv_ex - set an environment variable on the channel
libssh2_channel_request_pty_ex - request a terminal on a channel
libssh2_channel_process_startup - request a shell on a channel
libssh2_channel_read_ex - read from a channel
libssh2_channel_write_ex - write to a channel
libssh2_channel_handle_extended_data - set extended data handling mode
libssh2_channel_flush_ex - flush a channel
libssh2_channel_set_blocking - enable or disable blocking on a channel
libssh2_channel_eof - check a channel's EOF status
libssh2_channel_send_eof - send EOF to remote server
libssh2_channel_close - close a channel
libssh2_channel_free - free all resources associated with a channel
libssh2_channel_direct_tcpip_ex - Tunnel a TCP connection through an SSH session
libssh2_channel_forward_listen_ex - set up a forwarded TCP port
libssh2_channel_forward_cancel - cancel a forwarded TCP port
libssh2_channel_forward_accept - accept a connection on a TCP port
4. SCP
libssh2_scp_recv - request a remote file via SCP
libssh2_scp_send_ex - Send a file via SCP
5. SFTP
libssh2_sftp_init - start an SFTP session
libssh2_sftp_shutdown - shut down an SFTP session
libssh2_sftp_open_ex - open and possibly create a file on a remote host
libssh2_sftp_read - read from an SFTP file handle
libssh2_sftp_readdir - read an entry from an SFTP directory
libssh2_sftp_write - write data to an SFTP file handle
libssh2_sftp_fstat_ex - get or set attributes on a file handle
libssh2_sftp_seek - set the read/write position indicator to a position within a file
libssh2_sftp_tell - get the current read/write position indicator for a file
libssh2_sftp_close_handle - close filehandle
libssh2_sftp_unlink_ex - delete a file
libssh2_sftp_rename_ex - rename a file
libssh2_sftp_mkdir_ex - create a directory
libssh2_sftp_rmdir_ex - remove a directory
libssh2_sftp_stat_ex - get or set attributes on a file or symbolic link
libssh2_sftp_symlink_ex - read or set a symbolic link
libssh2_sftp_realpath - resolve a filename's path
libssh2_sftp_last_error - return the last SFTP-specific error code
6. Symbols
7. About this document

Chapter 1. Session operations

Table of Contents

libssh2_session_init_ex - initialize a libssh2 session handle
libssh2_banner_set - set the SSH prococol banner for the local client
libssh2_session_method_pref - set preferred key exchange method
libssh2_session_methods - return the currently active algorithms
libssh2_session_callback_set - set a callback function
libssh2_session_startup - start ssh2 on a socket
libssh2_session_disconnect_ex - disconnect a session
libssh2_session_abstract - return a pointer to a session's abstract pointer
libssh2_session_free - close all channels in a session, and free all associated memory
libssh2_session_last_error - return the last error code

Name

libssh2_session_init_ex — initialize a libssh2 session handle

Synopsis

#include <libssh2.h>

LIBSSH2_SESSION * libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC *allocfunc,
                                          LIBSSH2_FREE_FUNC *freefunc,
                                          LIBSSH2_REALLOC_FUNC *reallocfunc
                                          void *data);

LIBSSH2_SESSION * libssh2_session_init();

Description

The libssh2_session_init_ex() function initializes an SSH2 session and returns a session handle of type LIBSSH2_SESSION. If provided, libssh2 will use the allocfunc, freefunc and reallocfunc parameters for all internal memory management calls. In this case, the data parameter may optionally be passed to the provided callbacks.

As a convenience, the libssh2_session_init() macro is provided, which uses the system's memory management.


Name

libssh2_banner_set — set the SSH prococol banner for the local client

Synopsis

#include <libssh2.h>
#include <libssh2_sftp.h>

int libssh2_banner_set(LIBSSH2_SESSION *session, char *banner);

Description

This function sets the banner that will be sent to the remote host when the SSH session is started with libssh2_session_startup(). This is optional; a banner corresponding to the protocol and libssh2 version will be sent by default.

On success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() may be called to retrieve the error that occurred.


Name

libssh2_session_method_pref — set preferred key exchange method

Synopsis

#include <libssh2.h>

int libssh2_session_method_pref(LIBSSH2_SESSION *session,
                                int method_type,
                                char *prefs);

Description

This function sets preferred methods for key exchange and related algorithms for session. method_type denotes the type of preference to set, and prefs contains a comma-separated list of methods relevant to that preference. method_type may be one of the following:

LIBSSH2_METHOD_KEX

Key exchange method names. Supported values:

diffie-hellman-group1-sha1

Diffie-Hellman key exchange with SHA-1 as hash, and Oakley Group 2 (see RFC 2409).

diffie-hellman-group14-sha1

Diffie-Hellman key exchange with SHA-1 as hash, and Oakley Group 14 (see RFC 3526).

diffie-hellman-group-exchange-sha1

Diffie-Hellman key exchange with SHA-1 as hash, using a safe-prime/generator pair (chosen by server) of arbitrary strength (specified by client). (see ietf draft secsh-dh-group-exchange)

LIBSSH2_METHOD_HOSTKEY

Public key algorithms. Supported values:

ssh-dss

Based on the Digital Signature Standard (FIPS-186-2)

ssh-rsa

Based on PKCS#1 (RFC 3447)

LIBSSH2_METHOD_CRYPT_CS

Encryption algorithm from client to server. Supported algorithms:

aes256-cbc

AES in CBC mode, with 256-bit key

rijndael-cbc@lysator.liu.se

Alias for aes256-cbc

aes192-cbc

AES in CBC mode, with 192-bit key

aes128-cbc

AES in CBC mode, with 128-bit key

blowfish-cbc

Blowfish in CBC mode

arcfour

ARCFOUR stream cipher

cast128-cbc

CAST-128 in CBC mode

3des-cbc

three-key 3DES in CBC mode

none

No encyption

LIBSSH2_METHOD_CRYPT_SC

Encryption algorithm from server to client. See LIBSSH2_METHOD_CRYPT_CS for supported algorithms.

LIBSSH2_METHOD_MAC_CS

Message Authentication Code (MAC) algorithms from client to server. Supported values:

hmac-sha1

SHA-1 with 20-byte digest and key length

hmac-sha1-96

SHA-1 with 20-byte key length and 12-byte digest length

hmac-md5

MD5 with 16-byte digest and key length

hmac-md5-96

MD5 with 16-byte key length and 12-byte digest length

hmac-ripemd160

RIPEMD-160 algorithm with 20-byte digest length

hmac-ripemd160@openssh.com

Alias for hmac-ripemd160

none

LIBSSH2_METHOD_MAC_SC

Message Authentication Code (MAC) algorithms from server to client. See LIBSSH2_METHOD_MAC_SC for supported algorithms.

LIBSSH2_METHOD_COMP_CS

Compression methods from client to server. Supported values:

zlib

The "zlib" compression method as described in RFC 1950 and RFC 1951

none

No compression

LIBSSH2_METHOD_COMP_SC

Compression methods from server to client. See LIBSSH2_METHOD_COMP_CS for supported compression methods.

If successful, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() must be used to find out the error that occurred.


Name

libssh2_session_methods — return the currently active algorithms

Synopsis

#include <libssh2.h>

char *libssh2_session_methods(LIBSSH2_SESSION *session, int method_type);

Description

This function returns the methods currently active on session for the given method_type. For a list of valid method_type values, see libssh2_session_method_pref().

If successful, a pointer to a comma-separated list of active methods is returned. In case of failure, NULL is returned and libssh2_session_last_error() must be used to find out the error that occurred.

The returned pointer must NOT be freed.


Name

libssh2_session_callback_set — set a callback function

Synopsis

#include <libssh2.h>

void* libssh2_session_callback_set(LIBSSH2_SESSION *session,
                                   int cbtype, void *callback);

Description

This function sets a callback function for various events related to session. The cbtype parameter may be one of the following values:

LIBSSH2_CALLBACK_IGNORE

Called when an SSH_MSG_IGNORE packet is received. message/message_len represent the entire payload portion of the packet after decryption and decompression. See LIBSSH2_IGNORE_FUNC.

LIBSSH2_CALLBACK_DEBUG

Called when an SSH_MSG_DEBUG packet is received. See LIBSSH2_DEBUG_FUNC.

LIBSSH2_CALLBACK_DISCONNECT

Called when an SSH_MSG_DISCONNECT packet is received. reason corresponds to the SSH Disconnect Codes. If the connection is uncleanly terminated then this callback will not be triggered. See LIBSSH2_DISCONNECT_FUNC.

LIBSSH2_CALLBACK_MACERROR

Called when a Message Authentication Code (MAC) error occurs at any time during the session lifetime. See LIBSSH2_MACERROR_FUNC.

On success, the previous callback for the given cbtype is returned. Otherwise, NULL is returned.


Name

libssh2_session_startup — start ssh2 on a socket

Synopsis

#include <libssh2.h>

int libssh2_session_startup(LIBSSH2_SESSION *session, int socket);

Description

This function starts the SSH2 protocol on an existing socket, and associates it with session.

On success, 0 is returned. On error, one of the errorcodes below is returned indicating the specific error that occurred.


Name

libssh2_session_disconnect_ex — disconnect a session

Synopsis

#include <libssh2.h>

int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, char *description, char *lang);

int libssh2_session_disconnect(LIBSSH2_SESSION *session, char *description);

Description

libssh2_session_disconnect_ex() sends a disconnect message to the remote host associated with session, along with a reason symbol and a verbose description.

As a convenience, the macro libssh2_session_disconnect() is provided. It calls libssh2_session_disconnect_ex() with reason set to SSH_DISCONNECT_BY_APPLICATION and lang set to an empty string.

On success, 0 is returned. In case of error, -1 is returned, and the errorcode can be retrieved with libssh2_session_last_error().


Name

libssh2_session_abstract — return a pointer to a session's abstract pointer

Synopsis

#include <libssh2.h>

void **libssh2_session_abstract(LIBSSH2_SESSION *session);

Description

This function returns a void** pointer to the void *abstract value passed to libssh2_session_init_ex().


Name

libssh2_session_free — close all channels in a session, and free all associated memory

Synopsis

#include <libssh2.h>

void libssh2_session_free(LIBSSH2_SESSION *session);

Description

This function closes all channels in session, and frees all memory associated with the session, as well as any channels in it.


Name

libssh2_session_last_error — return the last error code

Synopsis

#include <libssh2.h>

int libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_len, int want_buf);

Description

This function returns session's last error code reported by a previous libssh2 function call. A verbose description of the specific error is copied into errmsg, up to errmsg_len bytes. If want_buf is non-zero, the string placed into errmsg must be freed by the calling program. Otherwise it is assumed to be owned by libssh2.

Chapter 2. Authentication

Table of Contents

libssh2_hostkey_hash - return a hash of the remote host's key
libssh2_userauth_password_ex - authenticate a session with username and password
libssh2_userauth_publickey_fromfile - authenticate a session with a public key, read from a file
libssh2_userauth_list - list the authentication methods supported by a server
libssh2_userauth_authenticated - return authentication status

Name

libssh2_hostkey_hash — return a hash of the remote host's key

Synopsis

#include <libssh2.h>

unsigned char * libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hashtype);

Description

This function returns a hash of the remote host's key . A session with the remote host should be established beforehand, by calling libssh2_session_startup(). The hashtype can be determined by passing one of the following:

If an error occurs, NULL will be returned.

The returned string is not NULL-terminated. The length of the returned string is either 16 bytes in case of MD5, or 20 bytes when SHA1 is used. The returned string is static storage, and must not be freed.


Name

libssh2_userauth_password_ex — authenticate a session with username and password

Synopsis

#include <libssh2.h>

int libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
                                  char *username, int username_len,
                                  char *password, int password_len,
                                  LIBSSH2_PASSWD_CHANGEREQ_FUNC *passwdchangefunc);

int libssh2_userauth_password(LIBSSH2_SESSION *session, char *username, char *password);

Description

The libssh2_userauth_password_ex() function authenticates a session using username and password of length username_len and password_len, respectively. passwdchangefunc will be called if the remote host requests a password change.

As a convenience, the libssh2_userauth_password() macro is provided, which works out the lengths of the username and password provided, and supplies to callback function for changing the password on request. In this case, the LIBSSH2_ERROR_PASSWORD_EXPIRED error code will be returned.

If successful, 0 is returned. In case of error, -1 is returned and libssh2_session_last_error() will returned the error that occurred. See below for a list of errorcodes that may be returned.


Name

libssh2_userauth_publickey_fromfile — authenticate a session with a public key, read from a file

Synopsis

#include <libssh2.h>

int libssh2_userauth_publickey_fromfile(LIBSSH2_SESSION *session,
                                        char *username,
                                        char *publickey, char *privatekey, char *passphrase);

Description

This function authenticates a session as username using a key pair found in the publickey and privatekey files, and passphrase if provided.

0 is returned if authentication succeeds. In case of error, -1 is returned, and libssh2_session_last_error() will return one of the errorcodes below.


Name

libssh2_userauth_list — list the authentication methods supported by a server

Synopsis

#include <libssh2.h>

char *libssh2_userauth_list(LIBSSH2_SESSION *session,
                            char *username, int username_len);

Description

This function provides a list of authentication methods supported by the server associated with session. An optional username may be provided, the length of which is passed in username_len.

On success, a NULL-terminated string containing a comma-separated list of authentication methods is returned. This string must be freed after use.

If the server accepts an unauthenticated session for the given username, NULL is returned and libssh2_userauth_authenticated() will return a non-zero value.

If an error occurred, NULL will be returned and libssh2_session_last_error() must be used to find out which error occurred.


Name

libssh2_userauth_authenticated — return authentication status

Synopsis

#include <libssh2.h>

int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);

Description

This function returns 0 if session is not yet authenticated, and non-zero if it is.

Errors

    Chapter 3. Channel operations

    Table of Contents

    libssh2_channel_open_ex - establish a generic session channel
    libssh2_channel_setenv_ex - set an environment variable on the channel
    libssh2_channel_request_pty_ex - request a terminal on a channel
    libssh2_channel_process_startup - request a shell on a channel
    libssh2_channel_read_ex - read from a channel
    libssh2_channel_write_ex - write to a channel
    libssh2_channel_handle_extended_data - set extended data handling mode
    libssh2_channel_flush_ex - flush a channel
    libssh2_channel_set_blocking - enable or disable blocking on a channel
    libssh2_channel_eof - check a channel's EOF status
    libssh2_channel_send_eof - send EOF to remote server
    libssh2_channel_close - close a channel
    libssh2_channel_free - free all resources associated with a channel
    libssh2_channel_direct_tcpip_ex - Tunnel a TCP connection through an SSH session
    libssh2_channel_forward_listen_ex - set up a forwarded TCP port
    libssh2_channel_forward_cancel - cancel a forwarded TCP port
    libssh2_channel_forward_accept - accept a connection on a TCP port

    Name

    libssh2_channel_open_ex — establish a generic session channel

    Synopsis

    #include <libssh2.h>
    
    LIBSSH2_CHANNEL *libssh2_channel_ex(LIBSSH2_SESSION *session,
                                        char *channel_type, int channel_type_len,
                                        int window_size,
                                        int packet_size);
    
    LIBSSH2_CHANNEL *libssh2_channel_open_session(LIBSSH2_SESSION *session);
    
    

    Description

    The libssh2_channel_open_ex() function opens a generic channel on the given session. The channel_type is according to the SSH2 specification, for example "session". channel_type_len is the length of the channel_type string. window_size specifies the inital window size for the new channel, and packet_size sets the maximum packet size to be sent over the channel.

    As a convencience, the libssh2_channel_open_session() macro is provided, which defaults channel_type to "session", window_size to 65536 and packet_size to 16384.

    On success, a new LIBSSH2_CHANNEL handle is returned. In case of error, NULL is returned, and the error can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_setenv_ex — set an environment variable on the channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL,
                                  char *varname, int varname_len,
                                  char *value, int value_len);
    
    int libssh2_channel_setenv(LIBSSH2_CHANNEL, char *varname, char *value);
    
    

    Description

    The libssh2_channel_setenv_ex() function sets environment variable varname to value on channel. varname_len and value_len are the lengths of the respective variables.

    As a convenience, the libssh2_channel_setenv() macro is provided, which fills in the lengths of varname and value.

    If successful, 0 is returned. In case of error, or the remote host refuses to allow this environment variable to be set, -1 is returned and the errorcode can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_request_pty_ex — request a terminal on a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL,
                                       char *terminaltype, int terminaltype_len
                                       char *modes, int modes_len,
                                       int width, int height,
                                       int width_px, int height_px);
    
    int libssh2_channel_request_pty(LIBSSH2_CHANNEL, char *terminaltype);
    
    

    Description

    The libssh2_channel_request_pty_ex() function requests a terminal on the channel. The terminaltype is a terminal identifier from termcap or terminfo, and terminaltype_len is the length of this string. It will be made available as the TERM environment variable.

    The optional width_px and height_px parameters inform the remote end of the local terminal's dimensions in pixels. If provided, the width and height parameters override width_px and height_px, and specify the dimensions of the local terminal in characters.

    The modes parameter is used to communicate to the remote host the capabilities the local terminal supports. Refer to the SSH Connection Protocol standard for detailed information on this parameter. modes_len specifies the length of the modes parameter.

    As a convenience, the libssh2_channel_request_pty() function is provided, which supplies the length of the passed in terminaltype parameter, sets width to 80 and height to 24.

    On success, 0 is returned. In case of failure, -1 is returned and the error can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_process_startup — request a shell on a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_process_startup(LIBSSH2_CHANNEL,
                                        char *request, int request_len,
                                        char *message, int message_len);
    
    int libssh2_channel_shell(LIBSSH2_CHANNEL);
    
    int libssh2_channel_exec(LIBSSH2_CHANNEL, char *command);
    
    int libssh2_channel_subsystem(LIBSSH2_CHANNEL, char *subsystem);
    
    

    Description

    libssh2_channel_process_startup() starts a process on the remote host associated with channel. The process type is passed in request, and an optional message, specific to the request, may be passed. request_len and message_len are the lengths of the respective parameters.

    As a convenience, the following macros are defined:

    libssh2_channel_shell() starts a shell on the remote host.

    libssh2_channel_exec() runs command on the remote host.

    libssh2_channel_subsystem() runs subsystem on the remote host.

    On success, 0 is returned. In case of failure, -1 is returned and the errorcode can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_read_ex — read from a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen);
    
    int libssh2_channel_read(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
    
    int libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
    
    

    Description

    libssh2_channel_read_ex() reads up to buflen bytes from channel, and stores these in buf. The stream_id can be either 0 to read from the channel's standard input, or SSH_EXTENDED_DATA_STDERR, for the channel's standard error. The number of bytes read is returned.

    As a convenience, the macros libssh2_channel_read() and libssh2_channel_read_stderr() are provided. These call libssh2_channel_read_ex() with stream_id set to the channel's standard output and standard error, respectively.


    Name

    libssh2_channel_write_ex — write to a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen);
    
    int libssh2_channel_write(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
    
    int libssh2_channel_write_stderr(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
    
    

    Description

    libssh2_channel_write_ex() writes buflen bytes from buf to a channel. The stream_id can be either 0 to write to the channel's standard output, or SSH_EXTENDED_DATA_STDERR, for the channel's standard error.

    As a convenience, the macros libssh2_channel_write() and libssh2_channel_write_stderr() are provided. These call libssh2_channel_write_ex() with stream_id set to the channel's standard output and standard error, respectively.

    Returns the number of bytes written if successful, or -1 in case of error. In this case, the errorcode can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_handle_extended_data — set extended data handling mode

    Synopsis

    #include <libssh2.h>
    
    void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
    
    

    Description

    This function sets the extended data behaviour on channel. ignore_mode may be one of the following:

    LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL

    Keep data in separate channels, i.e. use libssh2_channel_read_stderr() to read extended data. This is the default.

    LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE

    Ignore all extended data.

    LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE

    Merge extended data into regular channel input.


    Name

    libssh2_channel_flush_ex — flush a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int streamid);
    
    int libssh2_channel_flush(LIBSSH2_CHANNEL *channel);
    
    int libssh2_channel_flush_stderr(LIBSSH2_CHANNEL *channel);
    
    

    Description

    This function flushes all queued data on channel. stream_id may be either 0 for the channel's stdout, or SSH_EXTENDED_DATA_STDERR for stderr.

    As a convenience, the libssh2_channel_flush() and libssh2_channel_flush_stderr() macros are provided, which set stream_id to the respective values.

    On success, the total number of bytes flushed is returned. In case of error, -1 is returned, and the error can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_set_blocking — enable or disable blocking on a channel

    Synopsis

    #include <libssh2.h>
    
    void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking);
    
    

    Description

    Turn or or off blocking on the specified channel. Set the blocking parameter to 1 or 0.


    Name

    libssh2_channel_eof — check a channel's EOF status

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
    
    

    Description

    This function returns non-zero if the remote server sent an EOF.


    Name

    libssh2_channel_send_eof — send EOF to remote server

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
    
    

    Description

    Send an EOF to the remote server on this channel.

    Returns 0 if successful, or -1 in case of failure. In this case, the errorcode can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_close — close a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
    
    

    Description

    This function closes the specified channel.

    On success, 0 is returned. In case of error, -1 is returned and the errorcode can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_free — free all resources associated with a channel

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
    
    

    Description

    This function releases all resources associated with the specified channel, closing it first if necessary.

    Returns 0 on success, and -1 in case of failure.


    Name

    libssh2_channel_direct_tcpip_ex — Tunnel a TCP connection through an SSH session

    Synopsis

    #include <libssh2.h>
    
    LIBSSH2_CHANNEL *libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session,
                                                     char *host, int port,
                                                     char *shost, int sport);
    
    LIBSSH2_CHANNEL *libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session,
                                                     char *host, int port);
    
    

    Description

    This function creates a TCP connection from the remote host associated with session to host on TCP port, and associates this connection with a new channel.

    The shost and sport parameters specify the address and port the remote host should bind to for this connection.

    As a convenience, the libssh2_channel_direct_tcpip() function is provided, which sets the shost and sport parameters to "127.0.0.1" and "22", respectively.

    On success, a new LIBSSH2_CHANNEL handle is returned. In case of error, NULL is returned, and the error can be retrieved with libssh2_session_last_error().


    Name

    libssh2_channel_forward_listen_ex — set up a forwarded TCP port

    Synopsis

    #include <libssh2.h>
    
    LIBSSH2_LISTENER *libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session,
                                                        char *host, int port,
                                                        int *bound_port,
                                                        int queue_maxsize);
    
    LIBSSH2_LISTENER *libssh2_channel_forward_listen(LIBSSH2_SESSION *session, int port);
    
    

    Description

    This function sets up a listening TCP port on the remote host, connections to which will be forwarded across the encrypted SSH2 session.

    The host parameter, if not NULL, represents the address the remote host will bind the port to. It defaults to "0.0.0.0". The port parameter specifies the port to listen on, but may be 0 if the server may choose a free port. In this case, the port that was bound is returned in the bound_port pointer, if not NULL. The queue_maxsize parameter specifies the maximum number of queued connection requests that will be allowed before the remote server refuses new connections on the port.

    As a convenience, the libssh2_channel_forward_listen() macro is provided, which sets the host and bound_port parameters to NULL, and the queue_maxsize parameter to 16.

    If successful, this function returns a LIBSSH2_LISTENER handle. In case of error, NULL is returned and libssh2_session_last_error() can be used to find out more details.


    Name

    libssh2_channel_forward_cancel — cancel a forwarded TCP port

    Synopsis

    #include <libssh2.h>
    
    int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
    
    

    Description

    This function cancels a previously request TCP port forwarding associated with listener.

    On success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() must be used to find out the error that occurred.


    Name

    libssh2_channel_forward_accept — accept a connection on a TCP port

    Synopsis

    #include <libssh2.h>
    
    LIBSSH2_CHANNEL *libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
    
    

    Description

    This function accepts an incoming connection on the forwarded TCP port associated with listener.

    On success, a new LIBSSH2_CHANNEL handle is returned. In case of error, NULL is returned.

    Chapter 4. SCP

    Table of Contents

    libssh2_scp_recv - request a remote file via SCP
    libssh2_scp_send_ex - Send a file via SCP

    Name

    libssh2_scp_recv — request a remote file via SCP

    Synopsis

    #include <libssh2.h>
    
    LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
                                      char *path,
                                      struct stat *sb);
    
    

    Description

    This function opens a channel on session and requests a file via the SCP protocol. The filename is passed in the path parameter. If the sb parameter is passed in, it should point to a stat structure, which will be filled in with the remote file's modification times, access times, and permission modes. See stat(2) for details on this structure.

    If successful, this function returns a LIBSSH2_CHANNEL pointer, via which the file can be retrieved with calls to libssh2_channel_read_ex(). In case of error, NULL is returned and libssh2_session_last_error() can be used to find out more details.


    Name

    libssh2_scp_send_ex — Send a file via SCP

    Synopsis

    #include <libssh2.h>
    
    LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
                                         char *path,
                                         int mode,
                                         size_t filesize,
                                         long mtime, long atime);
    
    LIBSSH2_CHANNEL *libssh2_scp_send(LIBSSH2_SESSION *session,
                                         char *path,
                                         int mode,
                                         size_t filesize);
    
    

    Description

    This function requests a file send via SCP to the remote host associated with session. The remote filename will be the same as (the basename of) path. The mode (permissions), filesize, mtime (last modification time) and atime (last access time) are passed to the remote host.

    As a convenience, the libssh2_scp_send() macro is provided, which sets the mtime and atime parameters to 0.

    This function returns a new LIBSSH2_CHANNEL handle, which should be used in successive calls to libssh2_channel_write_ex() to send the file. In case of error, NULL is returned and libssh2_session_last_error() can be used to find out more details.

    Chapter 5. SFTP

    Table of Contents

    libssh2_sftp_init - start an SFTP session
    libssh2_sftp_shutdown - shut down an SFTP session
    libssh2_sftp_open_ex - open and possibly create a file on a remote host
    libssh2_sftp_read - read from an SFTP file handle
    libssh2_sftp_readdir - read an entry from an SFTP directory
    libssh2_sftp_write - write data to an SFTP file handle
    libssh2_sftp_fstat_ex - get or set attributes on a file handle
    libssh2_sftp_seek - set the read/write position indicator to a position within a file
    libssh2_sftp_tell - get the current read/write position indicator for a file
    libssh2_sftp_close_handle - close filehandle
    libssh2_sftp_unlink_ex - delete a file
    libssh2_sftp_rename_ex - rename a file
    libssh2_sftp_mkdir_ex - create a directory
    libssh2_sftp_rmdir_ex - remove a directory
    libssh2_sftp_stat_ex - get or set attributes on a file or symbolic link
    libssh2_sftp_symlink_ex - read or set a symbolic link
    libssh2_sftp_realpath - resolve a filename's path
    libssh2_sftp_last_error - return the last SFTP-specific error code

    Name

    libssh2_sftp_init — start an SFTP session

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session);
    
    

    Description

    This function starts an SFTP channel on session.

    On success, a LIBSSH2_SFTP handle is returned. In case of failure, NULL is returned, and libssh2_session_last_error() can be used to retrieve the error that occurred.


    Name

    libssh2_sftp_shutdown — shut down an SFTP session

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp);
    
    

    Description

    This function shuts down the SFTP session on sftp.

    Returns 0 on success, and -1 in case of failure.


    Name

    libssh2_sftp_open_ex — open and possibly create a file on a remote host

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    LIBSSH2_SFTP_HANDLE *libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp,
                                              char *filename, int filename_len,
                                              unsigned long flags,
                                              long mode,
                                              int open_type);
    
    LIBSSH2_SFTP_HANDLE *libssh2_sftp_open(LIBSSH2_SFTP *sftp,
                                           char *filename,
                                           unsigned long flags,
                                           long mode);
    
    LIBSSH2_SFTP_HANDLE *libssh2_sftp_opendir(LIBSSH2_SFTP *sftp, char *path);
    
    

    Description

    The libssh2_sftp_open_ex() function attempts to open filename (with length filename_len) on the sftp session.

    The flags parameter is either 0, or a combination of the following:

    LIBSSH2_FXF_READ

    Open the file for reading (POSIX: O_RDONLY)

    LIBSSH2_FXF_WRITE

    Open the file for writing (POSIX: O_WRONLY)

    LIBSSH2_FXF_APPEND

    The file is opened in append mode (POSIX: O_APPEND)

    LIBSSH2_FXF_CREAT

    If the file does not exist, it will be created (POSIX: O_CREAT)

    SSH2_FXF_TRUNC

    If the file already exists, truncate it to 0 length (POSIX: O_TRUNC)

    SSH2_FXF_EXCL

    Attempts to acquire an exclusive write lock, when used together with SSH2_FXF_CREAT (POSIX: O_EXCL)

    The mode parameter is ignored if an existing file is opened. If a new file is created, it corresponds to the permissions field in a LIBSSH2_SFTP_ATTRIBUTES structure.

    The open_type parameter can be either LIBSSH2_SFTP_OPENFILE or LIBSSH2_SFTP_OPENDIR to open a file or directory, respectively.

    As a convenience, the libssh2_sftp_open() and libssh2_sftp_opendir() macros are provided. They fill in the filename_len and open_type parameters appropriately.

    On success, a new LIBSSH2_SFTP_HANDLE is returned. In case of failure, NULL is returned, and libssh2_session_last_error() can be used to retrieve the error that occurred.


    Name

    libssh2_sftp_read — read from an SFTP file handle

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    size_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen);
    
    

    Description

    This function reads up to buffer_maxlen bytes into buffer from handle.

    On success, the number of bytes read is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to retrieve the error that occurred.


    Name

    libssh2_sftp_readdir — read an entry from an SFTP directory

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_readdir(LIBSSH2_SFTP_HANDLE *handle,
                             char *buffer, size_t buffer_maxlen,
                             LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    

    Description

    This function reads an entry from the directory specified in LIBSSH2_SFTP_HANDLE. The filename is stored into buffer, which is buffer_maxlen bytes long. The file attributes are stored in attrs.

    On success, the length of the filename is returned. To get all the entries in a directory, call this function until 0 is returned. In case of error, -1 is returned, and libssh2_session_last_error() can be used to retrieve the error that occurred.

    NOTE: the returned filename is not NULL-terminated, this the returned filename length must be used.


    Name

    libssh2_sftp_write — write data to an SFTP file handle

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    size_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
                              const char *buffer, size_t count);
    
    

    Description

    This function writes count bytes from buffer to handle.

    The function returns the number of bytes written, or -1 in case of error. Use libssh2_session_last_error() to find out which erorr occurred.


    Name

    libssh2_sftp_fstat_ex — get or set attributes on a file handle

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle,
                              LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat);
    
    int libssh2_sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    int libssh2_sftp_fsetstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    

    Description

    If setstat is non-zero, this function passes the attrs structure to the remote host, to be set on the file associated with handle.

    If setstat is 0, the attrs structure will be filled with the attributes of the file associated with handle.

    As a convenience, the libssh2_sftp_fstat() and libssh2_sftp_fsetstat() macros are provided, which call libssh2_sftp_fstat_ex() with the setstat parameter set to 0 and 1, respectively.

    On success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred.


    Name

    libssh2_sftp_seek — set the read/write position indicator to a position within a file

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset);
    
    

    Description

    This function repositions the position indicator of the file associated with handle to offset.


    Name

    libssh2_sftp_tell — get the current read/write position indicator for a file

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle);
    
    

    Description

    This function returns the current read/write position indicator of the file associated with handle.


    Name

    libssh2_sftp_close_handle — close filehandle

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle);
    
    

    Description

    This function closes handle.

    If successful, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to retrieve the error that occurred.


    Name

    libssh2_sftp_unlink_ex — delete a file

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, char *filename, int filename_len)
    
    int libssh2_sftp_unlink(LIBSSH2_SFTP *sftp, char *filename)
    
    

    Description

    This function deletes filename (with length filename_len) from the remote server associated with sftp.

    As a convenience, the libssh2_sftp_unlink() macro is provided, which fills in the filename_len parameter appropriately.

    On success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred.


    Name

    libssh2_sftp_rename_ex — rename a file

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp,
                               char *source_filename, int source_filename_len,
                               char *dest_filename, int dest_filename_len,
                               long flags);
    
    int libssh2_sftp_rename(LIBSSH2_SFTP, char *source_filename, char *dest_filename);
    
    

    Description

    The libssh2_sftp_rename_ex() function renames source_filename to dest_filename on the server associated with sftp. source_filename_len and dest_filename_len specify the lengths of the corresponding parameters.

    The flags parameter is either 0, or a combination of the following:

    LIBSSH2_SFTP_RENAME_OVERWRITE

    Overwrite any existing file with the same name as dest_filename.

    LIBSSH2_SFTP_RENAME_ATOMIC

    If dest_filename already exists and this flag is specified, the rename will be done in an atomic operation.

    LIBSSH2_SFTP_RENAME_NATIVE

    The server is free to do the rename operation in whatever way it chooses. Any other set flags are to be taken as hints to the server.

    As a convenience, the libssh2_sftp_rename() macro is provided, which fills in source_filename_len and dest_filename_len with the appropriate values, and sets flags to all 3 options above.

    In case of success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred. If the error is LIBSSH2_ERROR_SFTP_PROTOCOL, the application may then call libssh2_sftp_last_error() to get the specific SFTP protocol error.


    Name

    libssh2_sftp_mkdir_ex — create a directory

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp,
                              char *path, int path_len,
                              long mode);
    
    int libssh2_sftp_mkdir(LIBSSH2_SFTP *sftp,
                           char *path, long mode);
    
    

    Description

    The libssh2_sftp_mkdir_ex() creates a directory on the server associated with sftp. The directory name is provided in path, and the length of this parameter is provided in path_len. The mode parameter corresponds to the POSIX standard st_mode field as defined in stat(2).

    As a convenience, the libssh2_sftp_mkdir() macro is provided, which supplies the appropriate value for path_len.

    On success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred. If the error is LIBSSH2_ERROR_SFTP_PROTOCOL, the application may then call libssh2_sftp_last_error() to get the specific SFTP protocol error.


    Name

    libssh2_sftp_rmdir_ex — remove a directory

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, char *path, int path_len);
    
    int libssh2_sftp_rmdir(LIBSSH2_SFTP *sftp, char *path);
    
    

    Description

    The libssh2_sftp_rmdir_ex() function removes a directory on the remote system associated with sftp. The directory name is provided in path, and the length of this parameter is provided in path_len.

    As a convenience, the libssh2_sftp_rmdir() macro is provided, which supplies the appropriate value for path_len.

    On success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred. If the error is LIBSSH2_ERROR_SFTP_PROTOCOL, the application may then call libssh2_sftp_last_error() to get the specific SFTP protocol error.


    Name

    libssh2_sftp_stat_ex — get or set attributes on a file or symbolic link

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp,
                             char *path, int path_len,
                             int stat_type,
                             LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    int libssh2_sftp_stat(LIBSSH2_SFTP *sftp,
                          char *path,
                          LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    int libssh2_sftp_lstat(LIBSSH2_SFTP *sftp,
                           char *path,
                           LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    int libssh2_sftp_setstat(LIBSSH2_SFTP *sftp,
                             char *path,
                             LIBSSH2_SFTP_ATTRIBUTES *attrs);
    
    

    Description

    The libssh2_sftp_stat_ex() function is used to get or set attributes on the remote host associated with sftp. The filename is provided in path, and the length of this string is in path_len. In case of a get operation, the attrs parameter will be filled in with the specified file's attributes. In case of a set operation, the attrs parameter holds the attributes that will be set on the remote file.

    The stat_type parameter may be one of the following:

    LIBSSH2_SFTP_SETSTAT

    The operation is a setstat.

    LIBSSH2_SFTP_LSTAT

    The operation is a get, and symbolic links will not be followed.

    LIBSSH2_SFTP_STAT

    The operation is a get, and symbolic links will be followed.

    As a convenience, the libssh2_sftp_setstat(), libssh2_sftp_lstat() and libssh2_sftp_stat() macros are provided. These provide the appropriate value for path_len and set stat_type to the corresponding value.

    In case of success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred. If the error is LIBSSH2_ERROR_SFTP_PROTOCOL, the application may then call libssh2_sftp_last_error() to get the specific SFTP protocol error.


    Name

    libssh2_sftp_symlink_ex — read or set a symbolic link

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp,
                                const char *path, int path_len,
                                char *target, int target_len,
                                int link_type);
    
    int libssh2_sftp_symlink(LIBSSH2_SFTP *sftp,
                             char *path,
                             char *target);
    
    int libssh2_sftp_readlink(LIBSSH2_SFTP *sftp,
                              char *path,
                              char *target, int max_target_len);
    
    

    Description

    The libssh2_sftp_symlink_ex() function is used to create or read a symbolic link on the remote server associated with sftp.

    The link_type parameter may be one of the following:

    LIBSSH2_SFTP_SYMLINK

    Create a symbolic link named path, pointing to the file provided in target. The path_len and target_len parameters should contain the length of the respective strings.

    LIBSSH2_SFTP_READLINK

    Read the target of the symbolic link named path, the length of which is given in path_len. The returned filename will be stored in the buffer pointed to by target. The length of this buffer is specified in target_len.

    LIBSSH2_SFTP_REALPATH

    See libssh2_sftp_realpath().

    As a convenience, the libssh2_sftp_symlink() and libssh2_sftp_readlink() macros are provided. These call libssh2_sftp_symlink_ex() with link_type set to the respective values.

    In case of success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred. If the error is LIBSSH2_ERROR_SFTP_PROTOCOL, the application may then call libssh2_sftp_last_error() to get the specific SFTP protocol error.


    Name

    libssh2_sftp_realpath — resolve a filename's path

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    int libssh2_sftp_realpath(LIBSSH2_SFTP *sftp,
                              char *path,
                              char *target, int max_target_len);
    
    

    Description

    This function resolves a filename into its real path. This can be used for converting pathnames containing any combination of "../" and relative path names into its absolute path. The filename to be resolved is passed in path. The returned filename will be stored in the buffer pointed to by target. The length of this buffer is specified in target_len.

    In case of success, 0 is returned. In case of failure, -1 is returned and libssh2_session_last_error() can be used to find out which error occurred. If the error is LIBSSH2_ERROR_SFTP_PROTOCOL, the application may then call libssh2_sftp_last_error() to get the specific SFTP protocol error.


    Name

    libssh2_sftp_last_error — return the last SFTP-specific error code

    Synopsis

    #include <libssh2.h>
    #include <libssh2_sftp.h>
    
    unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp);
    
    

    Description

    This function returns the last error specific to SFTP. The error codes are as defined in the SFTP File Transfer Protocol standard. See LIBSSH2_ERROR_SFTP_PROTOCOL for more information.

    Chapter 6. Symbols

    Data types. 

    LIBSSH2_SESSION

    libssh2 session handle

    LIBSSH2_CHANNEL

    libssh2 channel handle

    LIBSSH2_LISTENER

    libssh2 port forwarding handle

    LIBSSH2_SFTP

    libssh2 SFTP handle

    LIBSSH2_SFTP_HANDLE

    libssh2 SFTP file handle

    LIBSSH2_SFTP_ATTRIBUTES

    libssh2 SFTP file attribute structure

    unsigned long flags;
    
    unsigned long filesize;
    unsigned long uid, gid;
    unsigned long permissions;
    unsigned long atime, mtime;
    

    If the flags parameter is anded with one of the following symbols, the respective field in the LIBSSH2_SFTP_ATTRIBUTES structure is meaningful.

    LIBSSH2_SFTP_ATTR_SIZE

    The filesize parameter is valid.

    LIBSSH2_SFTP_ATTR_UIDGID

    The uid and gid (numeric user ID and group ID) parameters are valid.

    LIBSSH2_SFTP_ATTR_PERMISSIONS

    The permissions parameter is valid. This contains one or more of the following flags:

    S_IRWXU

    Mask for file owner permissions

    S_IRUSR

    Owner has read permission

    S_IWUSR

    Owner has write permission

    S_IXUSR

    Owner has execute permission

    S_IRWXG

    Mask for group permissions

    S_IRGRP

    Group has read permission

    S_IWGRP

    Group has write permission

    S_IXGRP

    Group has execute permission

    S_IRWXO

    Mask for permissions for others (not in group)

    S_IROTH

    Others have read permission

    S_IWOTH

    Others have write permisson

    S_IXOTH

    Others have execute permission

    LIBSSH2_SFTP_ATTR_ACMODTIME

    The atime and mtime parameters are valid. These represent the last access and modification time respectively, and are expressed as elapsed seconds since Jan 1, 1970 (UTC)

    Constants. 

    SSH2_EXTENDED_DATA_STDERR

    select channel's standard error output

    LIBSSH2_HOSTKEY_HASH_MD5

    use an MD5 hash

    LIBSSH2_HOSTKEY_HASH_SHA1

    use an SHA1 hash

    LIBSSH2_SFTP_OPENFILE

    open a regular file via SFTP

    LIBSSH2_SFTP_OPENDIR

    open a directory via SFTP

    LIBSSH2_SFTP_SETSTAT

    the stat operation is a set

    LIBSSH2_SFTP_LSTAT

    the stat operation is a set

    LIBSSH2_SFTP_STAT

    the stat operation is a set

    LIBSSH2_SFTP_REALPATH

    resolve any given filename into the real path

    LIBSSH2_SFTP_SYMLINK

    create a symbolic link

    LIBSSH2_SFTP_READLINK

    read the target of a symbolic link

    SSH protocol disconnect codes. 

    SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT

    SSH_DISCONNECT_PROTOCOL_ERROR

    SSH_DISCONNECT_KEY_EXCHANGE_FAILED

    SSH_DISCONNECT_RESERVED

    SSH_DISCONNECT_MAC_ERROR

    SSH_DISCONNECT_COMPRESSION_ERROR

    SSH_DISCONNECT_SERVICE_NOT_AVAILABLE

    SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED

    SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE

    SSH_DISCONNECT_CONNECTION_LOST

    SSH_DISCONNECT_BY_APPLICATION

    SSH_DISCONNECT_TOO_MANY_CONNECTIONS

    SSH_DISCONNECT_AUTH_CANCELLED_BY_USER

    SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE

    SSH_DISCONNECT_ILLEGAL_USER_NAME

    Function prototypes. 

    LIBSSH2_ALLOC_FUNC
    void *allocfunc(size_t count, void **data)
    LIBSSH2_FREE_FUNC
    void freefunc(void *ptr, void **data)
    LIBSSH2_REALLOC_FUNC
    void *reallocfunc(void *ptr, size_t count, void **data)
    LIBSSH2_PASSWD_CHANGEREQ_FUNC
    void passwdchangefunc(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, void **abstract)
    LIBSSH2_IGNORE_FUNC
    void ignorefunc(LIBSSH2_SESSION *session, const char *message, int message_len, void **abstract)
    LIBSSH2_DEBUG_FUNC
    void debugfunc(LIBSSH2_SESSION *session, int always_display, const char *message, int message_len, const char *language, int language_len,void **abstract)
    LIBSSH2_DISCONNECT_FUNC
    void disconnectfunc(LIBSSH2_SESSION *session, int reason, const char *message, int message_len, const char *language, int language_len, void **abstract)
    LIBSSH2_MACERROR_FUNC
    int macerrorfunc(LIBSSH2_SESSION *session, const char *packet, int packet_len, void **abstract)

    Error codes. 

    LIBSSH2_ERROR_SOCKET_NONE

    The socket is invalid.

    LIBSSH2_ERROR_BANNER_NONE

    No banner was received from the remote host.

    LIBSSH2_ERROR_BANNER_SEND

    Unable to send banner to remote host.

    LIBSSH2_ERROR_INVALID_MAC

    LIBSSH2_ERROR_KEX_FAILURE

    Encryption key exchange with the remote host failed.

    LIBSSH2_ERROR_ALLOC

    An internal memory allocation call failed.

    LIBSSH2_ERROR_SOCKET_SEND

    Unable to send data on socket.

    LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE

    LIBSSH2_ERROR_TIMEOUT

    LIBSSH2_ERROR_HOSTKEY_INIT

    LIBSSH2_ERROR_HOSTKEY_SIGN

    LIBSSH2_ERROR_DECRYPT

    LIBSSH2_ERROR_SOCKET_DISCONNECT

    The socket was disconnected.

    LIBSSH2_ERROR_PROTO

    An invalid SSH protocol response was received on the socket.

    LIBSSH2_ERROR_PASSWORD_EXPIRED

    LIBSSH2_ERROR_FILE

    LIBSSH2_ERROR_METHOD_NONE

    LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED

    The username/public key combination was invalid.

    LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED

    The username/public key combination was invalid, or the signature for the supplied public key was invalid.

    LIBSSH2_ERROR_CHANNEL_OUTOFORDER

    LIBSSH2_ERROR_CHANNEL_FAILURE

    LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED

    LIBSSH2_ERROR_CHANNEL_UNKNOWN

    LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED

    LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED

    LIBSSH2_ERROR_CHANNEL_CLOSED

    LIBSSH2_ERROR_CHANNEL_EOF_SENT

    LIBSSH2_ERROR_SCP_PROTOCOL

    LIBSSH2_ERROR_ZLIB

    LIBSSH2_ERROR_SOCKET_TIMEOUT

    LIBSSH2_ERROR_SFTP_PROTOCOL

    An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. In the last case, libssh2_sftp_last_error() will return one of the following error codes:

    LIBSSH2_FX_OK

    LIBSSH2_FX_EOF

    LIBSSH2_FX_NO_SUCH_FILE

    LIBSSH2_FX_PERMISSION_DENIED

    LIBSSH2_FX_FAILURE

    LIBSSH2_FX_BAD_MESSAGE

    LIBSSH2_FX_NO_CONNECTION

    LIBSSH2_FX_CONNECTION_LOST

    LIBSSH2_FX_OP_UNSUPPORTED

    LIBSSH2_FX_INVALID_HANDLE

    LIBSSH2_FX_NO_SUCH_PATH

    LIBSSH2_FX_FILE_ALREADY_EXISTS

    The file already exists.

    LIBSSH2_FX_WRITE_PROTECT

    LIBSSH2_FX_NO_MEDIA

    LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM

    LIBSSH2_FX_QUOTA_EXCEEDED

    LIBSSH2_FX_UNKNOWN_PRINCIPLE

    LIBSSH2_FX_LOCK_CONFlICT

    LIBSSH2_FX_DIR_NOT_EMPTY

    LIBSSH2_FX_NOT_A_DIRECTORY

    LIBSSH2_FX_INVALID_FILENAME

    LIBSSH2_FX_LINK_LOOP

    LIBSSH2_ERROR_REQUEST_DENIED

    The remote server refused the request.

    LIBSSH2_ERROR_METHOD_NOT_SUPPORTED

    The requested method is not supported.

    LIBSSH2_ERROR_INVAL

    The requested method type was invalid.

    Chapter 7. About this document

    This reference manual is copyright (c) 2005 by Bert Vermeulen. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Any comments and questions regarding this document should be sent to docs@libssh2.org.