libssh2_sftp_stat_ex(3)
π libssh2_sftp_stat_ex β get status about an SFTP file
okay bestie, so this is a page from the libssh2 manual, and it's literally about peeking at (or setting) the metadata of a file chilling on a remote SFTP server. it's giving detective energy πβ¨. come sit with me, i got you.
β¨ SYNOPSIS β¨
#include <libssh2.h>
#include <libssh2_sftp.h>
int
libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path,
unsigned int path_len, int stat_type,
LIBSSH2_SFTP_ATTRIBUTES *attrs);
π DESCRIPTION π
here's the whole cast of characters, one by one:
sftpβ the SFTP instance, as handed to you bylibssh2_sftp_init(3). she's the whole vibe, your connection to the server.pathβ the remote filesystem object you wanna stat / lstat / setstat. yep, that's the target. π―path_lenβ the length of the name of that remote filesystem object you're stat / lstat / setstat-ing. like, the actual character count. don't sleep on it.stat_typeβ this is the main character of the whole function ngl. it's one of three constants that decide what kind of stat operation happens:attrsβ a pointer to aLIBSSH2_SFTP_ATTRIBUTESstructure. depending on whatstat_typeis, you're either pulling file metadata into it or pushing metadata out of it. it's a two-way street bestie π«Ά
so, the tea: this function gets or sets statbuf type data on a remote filesystem object. and when you're getting statbuf data, the difference matters, okay? libssh2_sftp_stat(3) will follow all symlinks β she's nosy like that, she goes all the way to the end. meanwhile libssh2_sftp_lstat(3) will return data about the object actually encountered, even if that object happens to be a symlink. like, she reports on the link herself, no chasing. periodt. π
the LIBSSH2_SFTP_ATTRIBUTES struct looks exactly like this, no cap:
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;
libssh2_uint64_t filesize;
unsigned long uid;
unsigned long gid;
unsigned long permissions;
unsigned long atime;
unsigned long mtime;
};
okay important: if flags & ATTR_* bit is set, then the value in that struct is meaningful. otherwise? ignore it. she's not telling you anything, don't read into it. π
π₯ RETURN VALUE π₯
returns 0 on success, or negative on failure. it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. and yeah, LIBSSH2_ERROR_EAGAIN is a negative number, but it's not really a failure per se β it's more like "bestie i'm busy, try again in a sec" energy. don't panic. π
π ERRORS π
LIBSSH2_ERROR_ALLOCβ an internal memory allocation call failed. the memory said no. tragic.LIBSSH2_ERROR_SOCKET_SENDβ unable to send data on socket. the socket ghosted you.LIBSSH2_ERROR_SOCKET_TIMEOUTβ (yeah that's it, that's the description. iconic of them honestly.)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. so either the server sent nonsense back, or the server itself said "error". either way, not it. π
π SEE ALSO π
that's the whole page bestie, you ate it. this one's from the libssh2 manual, version 0.15, dated 1 Jun 2007 β yeah she's vintage but she still slays. now go stat something. ππ¦β¨
π¦ 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