libssh2_sftp_symlink_ex(3)

πŸ“¦
version 1.11.1 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

okay bestie, welcome to the libssh2 manual, this one's about symbolic links and she does BOTH jobs: reading them AND setting them. main character energy fr fr πŸ¦‹


✨ 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,
                        unsigned int path_len, char *target,
                        unsigned int target_len, int link_type);

✨ DESCRIPTION ✨

So basically this function does the whole symlink thing on the remote side β€” it either creates a symlink or reads out symlink info from over there. Slay. πŸ’…

  • sftp β€” the SFTP instance, the one you got back from libssh2_sftp_init(3) πŸ’«
  • path β€” the remote filesystem object you're either creating a symlink from, or resolving. pick your fighter.
  • path_len β€” how long that remote filesystem object's name is (the one you're creating a symlink from or resolving).
  • target β€” a pointer to a buffer. and here's the tea: what this buffer is FOR totally depends on what link_type is set to πŸ‘€
    • LIBSSH2_SFTP_SYMLINK β€” the remote filesystem object to link to.
    • LIBSSH2_SFTP_READLINK β€” a pre-allocated buffer that the symlink target gets resolved into.
    • LIBSSH2_SFTP_REALPATH β€” a pre-allocated buffer that the realpath target gets resolved into.
  • target_len β€” the length of the name of the remote filesystem target object.
  • link_type β€” one of those three constants we just talked about, and it decides the entire resulting behavior of this function. no pressure bestie 😭

These are convenience macros, and honestly they're the ones you'll actually be using:


✨ RETURN VALUE ✨

it depends on the vibe you picked:

  • With LIBSSH2_SFTP_SYMLINK, it returns 0 on success, or negative on failure.
  • With LIBSSH2_SFTP_READLINK or LIBSSH2_SFTP_REALPATH, it returns the number of bytes it copied into the target buffer (not counting the terminating zero), or negative on failure.

It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. And yes, LIBSSH2_ERROR_EAGAIN is a negative number, but ngl it's not really a failure per se, don't panic 🫢

From 1.2.8, LIBSSH2_ERROR_BUFFER_TOO_SMALL gets returned if the given target buffer is too small to fit the requested object name.


πŸ’€ BUG πŸ’€

Passing in a too small buffer when receiving data only results in libssh2 1.2.7 or earlier to not copy the entire data amount, and it is not possible for the application to tell when it happens!

that's it, that's the bug. silently truncating and refusing to tell you? it's giving toxic. 😭


✨ ERRORS ✨

  • LIBSSH2_ERROR_ALLOC β€” an internal memory allocation call failed. rip. πŸ’€
  • LIBSSH2_ERROR_SOCKET_SEND β€” unable to send data on socket.
  • LIBSSH2_ERROR_SOCKET_TIMEOUT β€” (no description given, she's mysterious like that) πŸ™ˆ
  • 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.

✨ SEE ALSO ✨


okay that's the whole page bestie, go forth and symlink responsibly 🌈⭐

libssh2 0.15 Β· 1 Jun 2007 β€” yeah she's vintage, but she ate and left no crumbs πŸ‘‘πŸ’–