libssh  0.11.0
The SSH library
Loading...
Searching...
No Matches
The SSH channel functions
Collaboration diagram for The SSH channel functions:

Functions

ssh_channel ssh_channel_new (ssh_session session)
 Allocate a new channel.
 
uint32_t ssh_channel_new_id (ssh_session session)
 
 SSH_PACKET_CALLBACK (ssh_packet_channel_open_conf)
 
 SSH_PACKET_CALLBACK (ssh_packet_channel_open_fail)
 
ssh_channel ssh_channel_from_local (ssh_session session, uint32_t id)
 
 SSH_PACKET_CALLBACK (channel_rcv_change_window)
 
 SSH_PACKET_CALLBACK (channel_rcv_data)
 
 SSH_PACKET_CALLBACK (channel_rcv_eof)
 
 SSH_PACKET_CALLBACK (channel_rcv_close)
 
 SSH_PACKET_CALLBACK (channel_rcv_request)
 
int channel_default_bufferize (ssh_channel channel, void *data, uint32_t len, bool is_stderr)
 
int ssh_channel_open_session (ssh_channel channel)
 Open a session channel (suited for a shell, not TCP forwarding).
 
int ssh_channel_open_auth_agent (ssh_channel channel)
 Open an agent authentication forwarding channel. This type of channel can be opened by a server towards a client in order to provide SSH-Agent services to the server-side process. This channel can only be opened if the client claimed support by sending a channel request beforehand.
 
int ssh_channel_open_forward (ssh_channel channel, const char *remotehost, int remoteport, const char *sourcehost, int localport)
 Open a TCP/IP forwarding channel.
 
int ssh_channel_open_forward_unix (ssh_channel channel, const char *remotepath, const char *sourcehost, int localport)
 Open a TCP/IP - UNIX domain socket forwarding channel.
 
void ssh_channel_free (ssh_channel channel)
 Close and free a channel.
 
void ssh_channel_do_free (ssh_channel channel)
 
int ssh_channel_send_eof (ssh_channel channel)
 Send an end of file on the channel.
 
int ssh_channel_close (ssh_channel channel)
 Close a channel.
 
int ssh_channel_flush (ssh_channel channel)
 
uint32_t ssh_channel_window_size (ssh_channel channel)
 Get the remote window size.
 
int ssh_channel_write (ssh_channel channel, const void *data, uint32_t len)
 Blocking write on a channel.
 
int ssh_channel_is_open (ssh_channel channel)
 Check if the channel is open or not.
 
int ssh_channel_is_closed (ssh_channel channel)
 Check if the channel is closed or not.
 
int ssh_channel_is_eof (ssh_channel channel)
 Check if remote has sent an EOF.
 
void ssh_channel_set_blocking (ssh_channel channel, int blocking)
 Put the channel into blocking or nonblocking mode.
 
 SSH_PACKET_CALLBACK (ssh_packet_channel_success)
 
 SSH_PACKET_CALLBACK (ssh_packet_channel_failure)
 
int ssh_channel_request_pty_size_modes (ssh_channel channel, const char *terminal, int col, int row, const unsigned char *modes, size_t modes_len)
 Request a pty with a specific type and size.
 
int ssh_channel_request_pty_size (ssh_channel channel, const char *terminal, int col, int row)
 
int ssh_channel_request_pty (ssh_channel channel)
 Request a PTY.
 
int ssh_channel_change_pty_size (ssh_channel channel, int cols, int rows)
 Change the size of the terminal associated to a channel.
 
int ssh_channel_request_shell (ssh_channel channel)
 Request a shell.
 
int ssh_channel_request_subsystem (ssh_channel channel, const char *subsys)
 Request a subsystem (for example "sftp").
 
int ssh_channel_request_sftp (ssh_channel channel)
 Request sftp subsystem on the channel.
 
int ssh_channel_request_x11 (ssh_channel channel, int single_connection, const char *protocol, const char *cookie, int screen_number)
 Sends the "x11-req" channel request over an existing session channel.
 
ssh_channel ssh_channel_accept_x11 (ssh_channel channel, int timeout_ms)
 Accept an X11 forwarding channel.
 
int ssh_channel_request_auth_agent (ssh_channel channel)
 Send an "auth-agent-req" channel request over an existing session channel.
 
 SSH_PACKET_CALLBACK (ssh_request_success)
 
 SSH_PACKET_CALLBACK (ssh_request_denied)
 
int ssh_channel_listen_forward (ssh_session session, const char *address, int port, int *bound_port)
 Sends the "tcpip-forward" global request to ask the server to begin listening for inbound connections.
 
int ssh_forward_listen (ssh_session session, const char *address, int port, int *bound_port)
 
ssh_channel ssh_forward_accept (ssh_session session, int timeout_ms)
 
ssh_channel ssh_channel_accept_forward (ssh_session session, int timeout_ms, int *destination_port)
 Accept an incoming TCP/IP forwarding channel and get some information about incoming connection.
 
ssh_channel ssh_channel_open_forward_port (ssh_session session, int timeout_ms, int *destination_port, char **originator, int *originator_port)
 Accept an incoming TCP/IP forwarding channel and get information about incoming connection.
 
int ssh_channel_cancel_forward (ssh_session session, const char *address, int port)
 Sends the "cancel-tcpip-forward" global request to ask the server to cancel the tcpip-forward request.
 
int ssh_forward_cancel (ssh_session session, const char *address, int port)
 
int ssh_channel_request_env (ssh_channel channel, const char *name, const char *value)
 Set environment variables.
 
int ssh_channel_request_exec (ssh_channel channel, const char *cmd)
 Run a shell command without an interactive shell.
 
int ssh_channel_request_send_signal (ssh_channel channel, const char *sig)
 Send a signal to remote process (as described in RFC 4254, section 6.9).
 
int ssh_channel_request_send_break (ssh_channel channel, uint32_t length)
 Send a break signal to the server (as described in RFC 4335).
 
int channel_read_buffer (ssh_channel channel, ssh_buffer buffer, uint32_t count, int is_stderr)
 Read data from a channel into a buffer.
 
int ssh_channel_read (ssh_channel channel, void *dest, uint32_t count, int is_stderr)
 Reads data from a channel.
 
int ssh_channel_read_timeout (ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms)
 Reads data from a channel.
 
int ssh_channel_read_nonblocking (ssh_channel channel, void *dest, uint32_t count, int is_stderr)
 Do a nonblocking read on the channel.
 
int ssh_channel_poll (ssh_channel channel, int is_stderr)
 Polls a channel for data to read.
 
int ssh_channel_poll_timeout (ssh_channel channel, int timeout, int is_stderr)
 Polls a channel for data to read, waiting for a certain timeout.
 
ssh_session ssh_channel_get_session (ssh_channel channel)
 Recover the session in which belongs a channel.
 
int ssh_channel_get_exit_state (ssh_channel channel, uint32_t *pexit_code, char **pexit_signal, int *pcore_dumped)
 Get the exit state of the channel (error code from the executed instruction or signal).
 
int ssh_channel_get_exit_status (ssh_channel channel)
 Get the exit status of the channel (error code from the executed instruction).
 
int ssh_channel_select (ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct timeval *timeout)
 Act like the standard select(2) on channels.
 
void ssh_channel_set_counter (ssh_channel channel, ssh_counter counter)
 Set the channel data counter.
 
int ssh_channel_write_stderr (ssh_channel channel, const void *data, uint32_t len)
 Blocking write on a channel stderr.
 
int ssh_channel_open_reverse_forward (ssh_channel channel, const char *remotehost, int remoteport, const char *sourcehost, int localport)
 Open a TCP/IP reverse forwarding channel.
 
int ssh_channel_open_x11 (ssh_channel channel, const char *orig_addr, int orig_port)
 Open a X11 channel.
 
int ssh_channel_request_send_exit_status (ssh_channel channel, int exit_status)
 Send the exit status to the remote process.
 
int ssh_channel_request_send_exit_signal (ssh_channel channel, const char *sig, int core, const char *errmsg, const char *lang)
 Send an exit signal to remote process (RFC 4254, section 6.10).
 

Detailed Description

Functions that manage a SSH channel.

Function Documentation

◆ channel_read_buffer()

int channel_read_buffer ( ssh_channel channel,
ssh_buffer buffer,
uint32_t count,
int is_stderr )

Read data from a channel into a buffer.

Parameters
[in]channelThe channel to read from.
[out]bufferThe buffer which will get the data.
[in]countThe count of bytes to be read. If it is bigger than 0, the exact size will be read, else (bytes=0) it will return once anything is available.
is_stderrA boolean value to mark reading from the stderr stream.
Returns
The number of bytes read, 0 on end of file, SSH_AGAIN on timeout and SSH_ERROR on error.
Deprecated
Please use ssh_channel_read instead
Warning
This function doesn't work in nonblocking/timeout mode
See also
ssh_channel_read

◆ ssh_channel_accept_forward()

ssh_channel ssh_channel_accept_forward ( ssh_session session,
int timeout_ms,
int * destination_port )

Accept an incoming TCP/IP forwarding channel and get some information about incoming connection.

Parameters
[in]sessionThe ssh session to use.
[in]timeout_msA timeout in milliseconds.
[in]destination_portA pointer to destination port or NULL.
Returns
Newly created channel, or NULL if no incoming channel request from the server

◆ ssh_channel_accept_x11()

ssh_channel ssh_channel_accept_x11 ( ssh_channel channel,
int timeout_ms )

Accept an X11 forwarding channel.

Parameters
[in]channelAn x11-enabled session channel.
[in]timeout_msTimeout in milliseconds.
Returns
A newly created channel, or NULL if no X11 request from the server.

◆ ssh_channel_cancel_forward()

int ssh_channel_cancel_forward ( ssh_session session,
const char * address,
int port )

Sends the "cancel-tcpip-forward" global request to ask the server to cancel the tcpip-forward request.

Parameters
[in]sessionThe ssh session to send the request.
[in]addressThe bound address on the server.
[in]portThe bound port on the server.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.

◆ ssh_channel_change_pty_size()

int ssh_channel_change_pty_size ( ssh_channel channel,
int cols,
int rows )

Change the size of the terminal associated to a channel.

Parameters
[in]channelThe channel to change the size.
[in]colsThe new number of columns.
[in]rowsThe new number of rows.
Returns
SSH_OK on success, SSH_ERROR if an error occurred.
Warning
Do not call it from a signal handler if you are not sure any other libssh function using the same channel/session is running at the same time (not 100% threadsafe).

◆ ssh_channel_close()

int ssh_channel_close ( ssh_channel channel)

Close a channel.

This sends an end of file and then closes the channel. You won't be able to recover any data the server was going to send or was in buffers.

Parameters
[in]channelThe channel to close.
Returns
SSH_OK on success, SSH_ERROR if an error occurred.
See also
ssh_channel_free()
ssh_channel_is_eof()

◆ ssh_channel_free()

void ssh_channel_free ( ssh_channel channel)

Close and free a channel.

Parameters
[in]channelThe channel to free.
Warning
Any data unread on this channel will be lost.

◆ ssh_channel_get_exit_state()

int ssh_channel_get_exit_state ( ssh_channel channel,
uint32_t * pexit_code,
char ** pexit_signal,
int * pcore_dumped )

Get the exit state of the channel (error code from the executed instruction or signal).

Parameters
[in]channelThe channel to get the status from.
[out]pexit_codeA pointer to an uint32_t to store the exit status.
[out]pexit_signalA pointer to store the exit signal as a string. The signal is without the SIG prefix, e.g. "TERM" or "KILL"). The caller has to free the memory.
[out]pcore_dumpedA pointer to store a boolean value if it dumped a core.
Returns
SSH_OK on success, SSH_AGAIN if we don't have a status or an SSH error.
Warning
This function may block until a timeout (or never) if the other side is not willing to close the channel. When a channel is freed the function returns SSH_ERROR immediately.

If you're looking for an async handling of this register a callback for the exit status!

See also
ssh_channel_exit_status_callback
ssh_channel_exit_signal_callback

◆ ssh_channel_get_exit_status()

int ssh_channel_get_exit_status ( ssh_channel channel)

Get the exit status of the channel (error code from the executed instruction).

Parameters
[in]channelThe channel to get the status from.
Returns
The exit status, -1 if no exit status has been returned (yet), or SSH_ERROR on error.
Warning
This function may block until a timeout (or never) if the other side is not willing to close the channel. When a channel is freed the function returns SSH_ERROR immediately.

If you're looking for an async handling of this register a callback for the exit status.

See also
ssh_channel_exit_status_callback
Deprecated
Please use ssh_channel_exit_state()

◆ ssh_channel_get_session()

ssh_session ssh_channel_get_session ( ssh_channel channel)

Recover the session in which belongs a channel.

Parameters
[in]channelThe channel to recover the session from.
Returns
The session pointer.

◆ ssh_channel_is_closed()

int ssh_channel_is_closed ( ssh_channel channel)

Check if the channel is closed or not.

Parameters
[in]channelThe channel to check.
Returns
0 if channel is opened, nonzero otherwise.
See also
ssh_channel_is_open()

◆ ssh_channel_is_eof()

int ssh_channel_is_eof ( ssh_channel channel)

Check if remote has sent an EOF.

Parameters
[in]channelThe channel to check.
Returns
0 if there is no EOF, nonzero otherwise.

◆ ssh_channel_is_open()

int ssh_channel_is_open ( ssh_channel channel)

Check if the channel is open or not.

Parameters
[in]channelThe channel to check.
Returns
0 if channel is closed, nonzero otherwise.
See also
ssh_channel_is_closed()

◆ ssh_channel_listen_forward()

int ssh_channel_listen_forward ( ssh_session session,
const char * address,
int port,
int * bound_port )

Sends the "tcpip-forward" global request to ask the server to begin listening for inbound connections.

Parameters
[in]sessionThe ssh session to send the request.
[in]addressThe address to bind to on the server. Pass NULL to bind to all available addresses on all protocol families supported by the server.
[in]portThe port to bind to on the server. Pass 0 to ask the server to allocate the next available unprivileged port number
[in]bound_portThe pointer to get actual bound port. Pass NULL to ignore.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.

◆ ssh_channel_new()

ssh_channel ssh_channel_new ( ssh_session session)

Allocate a new channel.

Parameters
[in]sessionThe ssh session to use.
Returns
A pointer to a newly allocated channel, NULL on error. The channel needs to be freed with ssh_channel_free().
See also
ssh_channel_free()

◆ ssh_channel_open_auth_agent()

int ssh_channel_open_auth_agent ( ssh_channel channel)

Open an agent authentication forwarding channel. This type of channel can be opened by a server towards a client in order to provide SSH-Agent services to the server-side process. This channel can only be opened if the client claimed support by sending a channel request beforehand.

Parameters
[in]channelAn allocated channel.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
See also
ssh_channel_open_forward()

◆ ssh_channel_open_forward()

int ssh_channel_open_forward ( ssh_channel channel,
const char * remotehost,
int remoteport,
const char * sourcehost,
int localport )

Open a TCP/IP forwarding channel.

Parameters
[in]channelAn allocated channel.
[in]remotehostThe remote host to connected (host name or IP).
[in]remoteportThe remote port.
[in]sourcehostThe numeric IP address of the machine from where the connection request originates. This is mostly for logging purposes.
[in]localportThe port on the host from where the connection originated. This is mostly for logging purposes.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Warning
This function does not bind the local port and does not automatically forward the content of a socket to the channel. You still have to use ssh_channel_read and ssh_channel_write for this.

◆ ssh_channel_open_forward_port()

ssh_channel ssh_channel_open_forward_port ( ssh_session session,
int timeout_ms,
int * destination_port,
char ** originator,
int * originator_port )

Accept an incoming TCP/IP forwarding channel and get information about incoming connection.

Parameters
[in]sessionThe ssh session to use.
[in]timeout_msA timeout in milliseconds.
[out]destination_portA pointer to destination port or NULL.
[out]originatorA pointer to a pointer to a string of originator host or NULL. That the caller is responsible for to ssh_string_free_char().
[out]originator_portA pointer to originator port or NULL.
Returns
Newly created channel, or NULL if no incoming channel request from the server
See also
ssh_string_free_char()

◆ ssh_channel_open_forward_unix()

int ssh_channel_open_forward_unix ( ssh_channel channel,
const char * remotepath,
const char * sourcehost,
int localport )

Open a TCP/IP - UNIX domain socket forwarding channel.

Parameters
[in]channelAn allocated channel.
[in]remotepathThe UNIX socket path on the remote machine
[in]sourcehostThe numeric IP address of the machine from where the connection request originates. This is mostly for logging purposes.
[in]localportThe port on the host from where the connection originated. This is mostly for logging purposes.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Warning
This function does not bind the local port and does not automatically forward the content of a socket to the channel. You still have to use ssh_channel_read and ssh_channel_write for this.
Requires support of OpenSSH for UNIX domain socket forwarding.

◆ ssh_channel_open_reverse_forward()

int ssh_channel_open_reverse_forward ( ssh_channel channel,
const char * remotehost,
int remoteport,
const char * sourcehost,
int localport )

Open a TCP/IP reverse forwarding channel.

Parameters
[in]channelAn allocated channel.
[in]remotehostThe remote host to connected (host name or IP).
[in]remoteportThe remote port.
[in]sourcehostThe source host (your local computer). It's optional and for logging purpose.
[in]localportThe source port (your local computer). It's optional and for logging purpose.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Warning
This function does not bind the local port and does not automatically forward the content of a socket to the channel. You still have to use ssh_channel_read and ssh_channel_write for this.

◆ ssh_channel_open_session()

int ssh_channel_open_session ( ssh_channel channel)

Open a session channel (suited for a shell, not TCP forwarding).

Parameters
[in]channelAn allocated channel.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
See also
ssh_channel_open_forward()
ssh_channel_request_env()
ssh_channel_request_shell()
ssh_channel_request_exec()

◆ ssh_channel_open_x11()

int ssh_channel_open_x11 ( ssh_channel channel,
const char * orig_addr,
int orig_port )

Open a X11 channel.

Parameters
[in]channelAn allocated channel.
[in]orig_addrThe source host (the local server).
[in]orig_portThe source port (the local server).
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Warning
This function does not bind the local port and does not automatically forward the content of a socket to the channel. You still have to use shh_channel_read and ssh_channel_write for this.

◆ ssh_channel_poll()

int ssh_channel_poll ( ssh_channel channel,
int is_stderr )

Polls a channel for data to read.

If callbacks are set on the channel, they will be called.

Parameters
[in]channelThe channel to poll.
[in]is_stderrA boolean to select the stderr stream.
Returns
The number of bytes available for reading, 0 if nothing is available or SSH_ERROR on error. When a channel is freed the function returns SSH_ERROR immediately.
Warning
When the channel is in EOF state, the function returns SSH_EOF.
See also
ssh_channel_is_eof()

◆ ssh_channel_poll_timeout()

int ssh_channel_poll_timeout ( ssh_channel channel,
int timeout,
int is_stderr )

Polls a channel for data to read, waiting for a certain timeout.

Parameters
[in]channelThe channel to poll.
[in]timeoutSet an upper limit on the time for which this function will block, in milliseconds. Specifying a negative value means an infinite timeout. This parameter is passed to the poll() function.
[in]is_stderrA boolean to select the stderr stream.
Returns
The number of bytes available for reading, 0 if nothing is available (timeout elapsed), SSH_EOF on end of file, SSH_ERROR on error.
Warning
When the channel is in EOF state, the function returns SSH_EOF. When a channel is freed the function returns SSH_ERROR immediately.
See also
ssh_channel_is_eof()

◆ ssh_channel_read()

int ssh_channel_read ( ssh_channel channel,
void * dest,
uint32_t count,
int is_stderr )

Reads data from a channel.

Parameters
[in]channelThe channel to read from.
[out]destThe destination buffer which will get the data.
[in]countThe count of bytes to be read.
[in]is_stderrA boolean value to mark reading from the stderr flow.
Returns
The number of bytes read, 0 on end of file, SSH_AGAIN on timeout and SSH_ERROR on error.
Warning
This function may return less than count bytes of data, and won't block until count bytes have been read.

◆ ssh_channel_read_nonblocking()

int ssh_channel_read_nonblocking ( ssh_channel channel,
void * dest,
uint32_t count,
int is_stderr )

Do a nonblocking read on the channel.

A nonblocking read on the specified channel. it will return <= count bytes of data read atomically. It will also trigger any callbacks set on the channel.

Parameters
[in]channelThe channel to read from.
[out]destA pointer to a destination buffer.
[in]countThe count of bytes of data to be read.
[in]is_stderrA boolean to select the stderr stream.
Returns
The number of bytes read, SSH_AGAIN if nothing is available, SSH_ERROR on error, and SSH_EOF if the channel is EOF.
See also
ssh_channel_is_eof()

◆ ssh_channel_read_timeout()

int ssh_channel_read_timeout ( ssh_channel channel,
void * dest,
uint32_t count,
int is_stderr,
int timeout_ms )

Reads data from a channel.

Parameters
[in]channelThe channel to read from.
[out]destThe destination buffer which will get the data.
[in]countThe count of bytes to be read.
[in]is_stderrA boolean value to mark reading from the stderr flow.
[in]timeout_msA timeout in milliseconds. A value of -1 means infinite timeout.
Returns
The number of bytes read, 0 on end of file, SSH_AGAIN on timeout, SSH_ERROR on error.
Warning
This function may return less than count bytes of data, and won't block until count bytes have been read.

◆ ssh_channel_request_auth_agent()

int ssh_channel_request_auth_agent ( ssh_channel channel)

Send an "auth-agent-req" channel request over an existing session channel.

This client-side request will enable forwarding the agent over an secure tunnel. When the server is ready to open one authentication agent channel, an ssh_channel_open_request_auth_agent_callback event will be generated.

Parameters
[in]channelThe channel to send signal.
Returns
SSH_OK on success, SSH_ERROR if an error occurred

◆ ssh_channel_request_env()

int ssh_channel_request_env ( ssh_channel channel,
const char * name,
const char * value )

Set environment variables.

Parameters
[in]channelThe channel to set the environment variables.
[in]nameThe name of the variable.
[in]valueThe value to set.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Warning
Some environment variables may be refused by security reasons.

◆ ssh_channel_request_exec()

int ssh_channel_request_exec ( ssh_channel channel,
const char * cmd )

Run a shell command without an interactive shell.

This is similar to 'sh -c command'.

Parameters
[in]channelThe channel to execute the command.
[in]cmdThe command to execute (e.g. "ls ~/ -al | grep -i reports").
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.

Example:

rc = ssh_channel_request_exec(channel, "ps aux");
if (rc > 0) {
return -1;
}
while ((rc = ssh_channel_read(channel, buffer, sizeof(buffer), 0)) > 0) {
if (fwrite(buffer, 1, rc, stdout) != (unsigned int) rc) {
return -1;
}
}
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd)
Run a shell command without an interactive shell.
Definition channels.c:2789
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
Reads data from a channel.
Definition channels.c:3051
See also
ssh_channel_request_shell()

◆ ssh_channel_request_pty()

int ssh_channel_request_pty ( ssh_channel channel)

Request a PTY.

Parameters
[in]channelThe channel to send the request.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
See also
ssh_channel_request_pty_size()

◆ ssh_channel_request_pty_size_modes()

int ssh_channel_request_pty_size_modes ( ssh_channel channel,
const char * terminal,
int col,
int row,
const unsigned char * modes,
size_t modes_len )

Request a pty with a specific type and size.

Parameters
[in]channelThe channel to send the request.
[in]terminalThe terminal type ("vt100, xterm,...").
[in]colThe number of columns.
[in]rowThe number of rows.
[in]modesEncoded SSH terminal modes for the PTY
[in]modes_lenNumber of bytes in 'modes'
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.

◆ ssh_channel_request_send_break()

int ssh_channel_request_send_break ( ssh_channel channel,
uint32_t length )

Send a break signal to the server (as described in RFC 4335).

Sends a break signal to the remote process. Note, that remote system may not support breaks. In such a case this request will be silently ignored.

Parameters
[in]channelThe channel to send the break to.
[in]lengthThe break-length in milliseconds to send.
Returns
SSH_OK on success, SSH_ERROR if an error occurred

◆ ssh_channel_request_send_exit_signal()

int ssh_channel_request_send_exit_signal ( ssh_channel channel,
const char * sig,
int core,
const char * errmsg,
const char * lang )

Send an exit signal to remote process (RFC 4254, section 6.10).

This sends the exit status of the remote process. Note, that remote system may not support signals concept. In such a case this request will be silently ignored.

Parameters
[in]channelThe channel to send signal.
[in]sigThe signal to send (without SIG prefix) (e.g. "TERM" or "KILL").
[in]coreA boolean to tell if a core was dumped
[in]errmsgA CRLF explanation text about the error condition
[in]langThe language used in the message (format: RFC 3066)
Returns
SSH_OK on success, SSH_ERROR if an error occurred

◆ ssh_channel_request_send_exit_status()

int ssh_channel_request_send_exit_status ( ssh_channel channel,
int exit_status )

Send the exit status to the remote process.

Sends the exit status to the remote process (as described in RFC 4254, section 6.10).

Parameters
[in]channelThe channel to send exit status.
[in]exit_statusThe exit status to send
Returns
SSH_OK on success, SSH_ERROR if an error occurred.

◆ ssh_channel_request_send_signal()

int ssh_channel_request_send_signal ( ssh_channel channel,
const char * sig )

Send a signal to remote process (as described in RFC 4254, section 6.9).

Sends a signal 'sig' to the remote process. Note, that remote system may not support signals concept. In such a case this request will be silently ignored.

Parameters
[in]channelThe channel to send signal.
[in]sigThe signal to send (without SIG prefix)

SIGABRT -> ABRT
SIGALRM -> ALRM
SIGFPE -> FPE
SIGHUP -> HUP
SIGILL -> ILL
SIGINT -> INT
SIGKILL -> KILL
SIGPIPE -> PIPE
SIGQUIT -> QUIT
SIGSEGV -> SEGV
SIGTERM -> TERM
SIGUSR1 -> USR1
SIGUSR2 -> USR2
Returns
SSH_OK on success, SSH_ERROR if an error occurred.

◆ ssh_channel_request_sftp()

int ssh_channel_request_sftp ( ssh_channel channel)

Request sftp subsystem on the channel.

Parameters
[in]channelThe channel to request the sftp subsystem.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Note
You should use sftp_new() which does this for you.

◆ ssh_channel_request_shell()

int ssh_channel_request_shell ( ssh_channel channel)

Request a shell.

Parameters
[in]channelThe channel to send the request.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.

◆ ssh_channel_request_subsystem()

int ssh_channel_request_subsystem ( ssh_channel channel,
const char * subsys )

Request a subsystem (for example "sftp").

Parameters
[in]channelThe channel to send the request.
[in]subsysThe subsystem to request (for example "sftp").
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
Warning
You normally don't have to call it for sftp, see sftp_new().

◆ ssh_channel_request_x11()

int ssh_channel_request_x11 ( ssh_channel channel,
int single_connection,
const char * protocol,
const char * cookie,
int screen_number )

Sends the "x11-req" channel request over an existing session channel.

This will enable redirecting the display of the remote X11 applications to local X server over a secure tunnel.

Parameters
[in]channelAn existing session channel where the remote X11 applications are going to be executed.
[in]single_connectionA boolean to mark only one X11 app will be redirected.
[in]protocolA x11 authentication protocol. Pass NULL to use the default value MIT-MAGIC-COOKIE-1.
[in]cookieA x11 authentication cookie. Pass NULL to generate a random cookie.
[in]screen_numberThe screen number.
Returns
SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.

◆ ssh_channel_select()

int ssh_channel_select ( ssh_channel * readchans,
ssh_channel * writechans,
ssh_channel * exceptchans,
struct timeval * timeout )

Act like the standard select(2) on channels.

The list of pointers are then actualized and will only contain pointers to channels that are respectively readable, writable or have an exception to trap.

Parameters
[in]readchansA NULL pointer or an array of channel pointers, terminated by a NULL.
[in]writechansA NULL pointer or an array of channel pointers, terminated by a NULL.
[in]exceptchansA NULL pointer or an array of channel pointers, terminated by a NULL.
[in]timeoutTimeout as defined by select(2).
Returns
SSH_OK on a successful operation, SSH_EINTR if the select(2) syscall was interrupted, then relaunch the function, or SSH_ERROR on error.

◆ ssh_channel_send_eof()

int ssh_channel_send_eof ( ssh_channel channel)

Send an end of file on the channel.

This doesn't close the channel. You may still read from it but not write.

Parameters
[in]channelThe channel to send the eof to.
Returns
SSH_OK on success, SSH_ERROR if an error occurred.

Example:

rc = ssh_channel_send_eof(channel);
if (rc == SSH_ERROR) {
return -1;
}
while(!ssh_channel_is_eof(channel)) {
rc = ssh_channel_read(channel, buf, sizeof(buf), 0);
if (rc == SSH_ERROR) {
return -1;
}
}
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel)
Send an end of file on the channel.
Definition channels.c:1360
LIBSSH_API int ssh_channel_close(ssh_channel channel)
Close a channel.
Definition channels.c:1421
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel)
Check if remote has sent an EOF.
Definition channels.c:1737
See also
ssh_channel_close()
ssh_channel_free()
ssh_channel_is_eof()

◆ ssh_channel_set_blocking()

void ssh_channel_set_blocking ( ssh_channel channel,
int blocking )

Put the channel into blocking or nonblocking mode.

Parameters
[in]channelThe channel to use.
[in]blockingA boolean for blocking or nonblocking.
Warning
A side-effect of this is to put the whole session in non-blocking mode.
See also
ssh_set_blocking()

◆ ssh_channel_set_counter()

void ssh_channel_set_counter ( ssh_channel channel,
ssh_counter counter )

Set the channel data counter.

struct ssh_counter_struct counter = {
.in_bytes = 0,
.out_bytes = 0,
.in_packets = 0,
.out_packets = 0
};
ssh_channel_set_counter(channel, &counter);
LIBSSH_API void ssh_channel_set_counter(ssh_channel channel, ssh_counter counter)
Set the channel data counter.
Definition channels.c:3730
Parameters
[in]channelThe SSH channel.
[in]counterCounter for bytes handled by the channel.

◆ ssh_channel_window_size()

uint32_t ssh_channel_window_size ( ssh_channel channel)

Get the remote window size.

This is the maximum amount of bytes the remote side expects us to send before growing the window again.

Parameters
[in]channelThe channel to query.
Returns
The remote window size
Warning
A nonzero return value does not guarantee the socket is ready to send that much data. Buffering may happen in the local SSH packet buffer, so beware of really big window sizes.
A zero return value means ssh_channel_write (default settings) will block until the window grows back.

◆ ssh_channel_write()

int ssh_channel_write ( ssh_channel channel,
const void * data,
uint32_t len )

Blocking write on a channel.

Parameters
[in]channelThe channel to write to.
[in]dataA pointer to the data to write.
[in]lenThe length of the buffer to write to.
Returns
The number of bytes written, SSH_ERROR on error.
See also
ssh_channel_read()

◆ ssh_channel_write_stderr()

int ssh_channel_write_stderr ( ssh_channel channel,
const void * data,
uint32_t len )

Blocking write on a channel stderr.

Parameters
[in]channelThe channel to write to.
[in]dataA pointer to the data to write.
[in]lenThe length of the buffer to write to.
Returns
The number of bytes written, SSH_ERROR on error.
See also
ssh_channel_read()