libssh2_sftp_fstat_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

πŸ’– libssh2_sftp_fstat_ex(3) β€” the libssh2 manual, but make it cute πŸ’–

okay bestie, sit down, hydrate, because we're learning about libssh2_sftp_fstat_ex from the libssh2 manual and honestly? it's giving ✨file handle metadata✨ and I'm obsessed.


🌸 NAME 🌸

libssh2_sftp_fstat_ex β€” get or set attributes on an SFTP 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)

#define libssh2_sftp_fstat(handle, attrs) \
    libssh2_sftp_fstat_ex((handle), (attrs), 0)
#define libssh2_sftp_fsetstat(handle, attrs) \
    libssh2_sftp_fstat_ex((handle), (attrs), 1)

like. the macros are literally just this one function with a 0 or a 1 tacked on. no cap. πŸŽ€


πŸ’… DESCRIPTION πŸ’…

  • handle β€” the SFTP File Handle, as returned by libssh2_sftp_open_ex(3) πŸ¦‹
  • attrs β€” a pointer to an LIBSSH2_SFTP_ATTRIBUTES structure, which is where file metadata gets read from or written into, depending on what setstat says πŸ’«
  • setstat β€” when this is non-zero, the file's metadata gets updated with the data found in attrs, following the values of attrs->flags and the other relevant member attributes. when it's zero, we're just reading, bestie πŸ™ˆ

so basically: get or set statbuf type data for a given LIBSSH2_SFTP_HANDLE instance. iconic. no notes. πŸ‘‘


🧚 DATA TYPES 🧚

LIBSSH2_SFTP_ATTRIBUTES is a typedefed struct, and here's exactly what it looks like:

struct _LIBSSH2_SFTP_ATTRIBUTES {

    /* If flags & ATTR_* bit is set, then the value in this
     * struct will be meaningful Otherwise it should be ignored
     */
    unsigned long flags;

    /* size of file, in bytes */
    libssh2_uint64_t filesize;

    /* numerical representation of the user and group owner of
     * the file
     */
    unsigned long uid, gid;

    /* bitmask of permissions */
    unsigned long permissions;

    /* access time and modified time of file */
    unsigned long atime, mtime;
};

you'll find a whole full set of defines and macros for identifying flags and permissions over in the libssh2_sftp.h header file, but here are some of the most common ones, bestie, because I got you πŸ’–


πŸ” Permission checks πŸ”

to check for specific user permissions, the set of defines follows the pattern LIBSSH2_SFTP_S_I<action><who> β€” where <action> is R, W or X for read, write and executable, and <who> is USR, GRP and OTH for user, group and other. so if you wanna check for a user readable file, you use the bit LIBSSH2_SFTP_S_IRUSR, and if you wanna see whether it's executable for other, you use LIBSSH2_SFTP_S_IXOTH, and so on and so on. periodt. ✨


πŸ“ File type checks πŸ“

to check for specific file types, you previously (as in, before libssh2 1.2.5) used the standard posix S_IS***() macros. but since 1.2.5, libssh2 offers its own set of macros for this functionality:

  • LIBSSH2_SFTP_S_ISLNK β€” test for a symbolic link πŸ”—
  • LIBSSH2_SFTP_S_ISREG β€” test for a regular file πŸ“„
  • LIBSSH2_SFTP_S_ISDIR β€” test for a directory πŸ“
  • LIBSSH2_SFTP_S_ISCHR β€” test for a character special file 🎭
  • LIBSSH2_SFTP_S_ISBLK β€” test for a block special file 🧱
  • LIBSSH2_SFTP_S_ISFIFO β€” test for a pipe or FIFO special file 🚰
  • LIBSSH2_SFTP_S_ISSOCK β€” test for a socket πŸ”Œ

🌈 RETURN VALUE 🌈

returns 0 on success, or a negative number on failure. it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. and okay, important note bestie: while LIBSSH2_ERROR_EAGAIN is a negative number, it's not really a failure per se. it's just doing its little thing. don't panic. πŸ’œ


πŸ’€ ERRORS πŸ’€

  • LIBSSH2_ERROR_ALLOC β€” an internal memory allocation call failed 😭
  • LIBSSH2_ERROR_SOCKET_SEND β€” unable to send data on socket πŸ“‘
  • LIBSSH2_ERROR_SOCKET_TIMEOUT β€” (no description given, it'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 🚨

⭐ AVAILABILITY ⭐

this function has been around since forever, fr fr. but most of the LIBSSH2_SFTP_S_* defines were introduced in libssh2 0.14, and the LIBSSH2_SFTP_S_IS***() macros were introduced in libssh2 1.2.5. so if you're on something ancient, vibe check your version first. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! this little cutie comes to you from libssh2 0.15, dated 1 Jun 2007 β€” yeah, she's vintage, she's iconic, she ate and left no crumbs πŸ‘‘βœ¨ mwah, go write some SFTP code, you've got this πŸ’…πŸ’–πŸŒΈ