libssh2_sftp_fstat_ex(3)
π 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 bylibssh2_sftp_open_ex(3)π¦attrsβ a pointer to anLIBSSH2_SFTP_ATTRIBUTESstructure, which is where file metadata gets read from or written into, depending on whatsetstatsays π«setstatβ when this is non-zero, the file's metadata gets updated with the data found inattrs, following the values ofattrs->flagsand 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 π ππΈ
π¦ 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