libssh2_channel_write_ex(3)
π libssh2_channel_write_ex(3) π
okay bestie, welcome to the libssh2 manual, page for libssh2_channel_write_ex β yes she's a mouthful, yes she's iconic, and yes we're gonna get through this together π«Ά
β¨ NAME β¨
libssh2_channel_write_ex β write data to a channel stream, blocking style π
πΈ SYNOPSIS πΈ
#include <libssh2.h>
ssize_t
libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
int stream_id, char *buf,
size_t buflen);
π¦ DESCRIPTION π¦
So basically, this function writes data to a channel stream. Every channel stream comes with one standard I/O substream, and that's the one where stream_id == 0. On top of that, you can have up to 2^32 extended data streams, and which one you're poking at is decided by whichever stream_id you pick. The SSH2 protocol currently says that stream ID 1 is the stderr substream, periodt.
Now the cast of characters, one by one:
channelβ the active channel stream you're writing to.stream_idβ the substream ID number, like0orSSH_EXTENDED_DATA_STDERR.bufβ a pointer to the buffer you wanna write.buflenβ how big the data you're writing is.
Also, heads up: libssh2_channel_write(3) and libssh2_channel_write_stderr(3) are just convenience macros for this function. Same energy, less typing. π
And here's the little performance tea: libssh2_channel_write_ex(3) will use as much of the buffer as it possibly can and shove it into a single SSH protocol packet. Which means β if you want maximum performance when you're sending bigger files β you should really try to always pass in at least 32K of data to this function. fr fr, 32K minimum, don't play with her. π₯
π RETURN VALUE π
You get back the actual number of bytes written, or a negative number if something went wrong. And if it would have blocked, you get LIBSSH2_ERROR_EAGAIN instead. Now listen β even though LIBSSH2_ERROR_EAGAIN is a negative number, it's not really a failure per se, so don't panic. She's just saying "not right now, babe". π
π ERRORS π
LIBSSH2_ERROR_ALLOCβ an internal memory allocation call failed. Rude.LIBSSH2_ERROR_SOCKET_SENDβ unable to send data on socket.LIBSSH2_ERROR_CHANNEL_CLOSEDβ the channel has been closed.LIBSSH2_ERROR_CHANNEL_EOF_SENTβ the channel has been requested to be closed.LIBSSH2_ERROR_BAD_USEβ this one can come back at you if you ignored a previous return forLIBSSH2_ERROR_EAGAINand, instead of sending the original buffer with the original size, you sent a new buffer with a different size. The way that is a you problem, bestie, she warned you. π
β οΈ real talk: thatLIBSSH2_ERROR_BAD_USEsituation is genuinely a thing that happens. If you gotLIBSSH2_ERROR_EAGAIN, come back with the same buffer and the same size. No swapping mid-retry, no cap.
π SEE ALSO π
and that's the whole page, you ate that π this was libssh2 version 0.15, dated 1 Jun 2007 β vintage but still serving, iykyk πβ¨
π¦ where this page comes from
- alpine 3.22: libssh2-doc 1.11.1-r3 Β· BSD-3-Clause
- alpine 3.23: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- alpine 3.24: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- arch rolling: libssh2 1.11.1-7 Β· BSD-3-Clause
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u1 Β· BSD3
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u2 Β· BSD3
- epel 10: libssh2-docs 1.11.1-9.el10_3 Β· BSD-3-Clause
- epel 9: libssh2-docs 1.11.1-9.el9 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-4.fc43 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-9.fc43 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-5.fc44 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-9.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- ubuntu questing: libssh2-1-dev 1.11.1-1build1
- ubuntu questing: libssh2-1-dev 1.11.1-1ubuntu0.25.10.2
- ubuntu resolute: libssh2-1-dev 1.11.1-1build2 Β· BSD3
- ubuntu resolute: libssh2-1-dev 1.11.1-1ubuntu0.26.04.4 Β· BSD3
- ubuntu stonking: libssh2-1-dev 1.11.1-6 Β· BSD3
- π the page's license: BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms